
; Asar directives
hirom
org $C30000
table ff6_bank_c3.tbl,rtl
incsrc ff6_bank_c3_defs.asm


; Entry points
C30000:  JMP C3001B      ; Invoke desired field menu
C30003:  JMP C3A445      ; Decode joypads for battle
C30006:  JMP C3A424      ; Initialize joypad data
C30009:  JMP C3A47A      ; Decode joypads for field
C3000C:  JMP C313C8      ; Advance play time
C3000F:  JMP C314FE      ; Load save data on defeat
C30012:  JMP C3C51C      ; Show an ending cinematic
C30015:  JMP C396D2      ; Optimize member's gear
C30018:  JMP C3D57F      ; Load map for final land

; Invoke requested field menu
C3001B:  REP #$10        ; 16-bit X, Y
         SEP #$20        ; 8-bit A
         PEI ($00)       ; Push #$0000
         PLD             ; Set DP to 0
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         JSR C300C0      ; Reroute NMI/IRQ
         LDA $0200       ; Menu to open
         CMP #$02        ; Load menu?
         BNE C3003F      ; Branch if not
         JSR C3709B      ; Reset game data
C3003F:  JSR C300F8      ; Load GFX, colors
         JSR C300DD      ; Handle menu
         JSL C3A424      ; Get joypad config
         JSR C3C576      ; Disable pad, etc.

; Fork: Leaving Load menu
C30057:  LDA $0200       ; Menu closed
         CMP #$02        ; Load menu?
         BNE C3006F      ; Branch if not
         LDA $0205       ; Start new game?
         BPL C3006F      ; Branch if so
         LDA $1D4E       ; Game options
         AND #$20        ; Stereo sound?
         BEQ C3006F      ; Branch if so
         LDA #$FF        ; Mode: Mono
         JSR C33E3F      ; Adjust volume

; Fork: Rename Card
C3006F:  LDA $0200       ; In main menu?
         BNE C300BF      ; Return if not
         LDA $0205       ; Rename request?
         BPL C300BF      ; Return if not
         CMP #$FE        ; Rename actor?
         BNE C3009E      ; SwdTech if not
         LDA $0201       ; Area permissions
         PHA             ; Preserve them
         LDY $0206       ; Actor's address
         STY $0201       ; Set as target's
         LDA #$01        ; Menu number
         BRA C300AF      ; Call naming menu

; Fork: SwdTech renaming (SFC)
C3009E:  LDA $0201       ; Area permissions
         PHA             ; Preserve them
         LDA $0206       ; Chosen SwdTech
         STA $0201       ; Set as target
         LDA #$06        ; SwdTech renaming
C300AF:  STA $0200       ; Set menu number
         JSL C30000      ; Call naming menu
         PLA             ; Area permissions
         STA $0201       ; Restore them
         STZ $0200       ; Menu: Main
         JMP C3001B      ; Open main menu
C300BF:  RTL

; Reroute interrupt vectors
C300C0:  LDA #$5C        ; JML opcode
         STA $1500       ; Put by NMI loc
         STA $1504       ; Put by IRQ loc
         LDX #C31387     ; C3/1387
         STX $1501       ; Set NMI LBs
         LDX #C313C7     ; C3/13C7
         STX $1505       ; Set IRQ LBs
         LDA #$C3        ; Bank: C3
         STA $1503       ; Set NMI HB
         STA $1507       ; Set IRQ HB
         RTS

; Access requested field menu
C300DD:  TDC             ; Clear A
         LDA $0200       ; Menu to open
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C300E6,X)  ; Invoke menu

; Jump table for the above
C300E6:  dw C3011A       ; Main menu
         dw C301B3       ; Actor naming
         dw C3016F       ; Load menu
         dw C30121       ; Shop
         dw C3012B       ; Lineup
         dw C30000       ; Bogus...
         dw C30149       ; SwdTech naming
         dw C30152       ; Colosseum
         dw C30166       ; Final battle lineup

; Load menu graphics and colors; initialize general variables
C300F8:  JSR C368FA      ; Reset variables
         JSR C36915      ; Get party info
;        JSR C369A9      ; No use...
         JSL $D4CD48     ; Init registers
         JSL C3A424      ; Init joypad data
         TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         JSR C369DC      ; Queue Win1 HDMA
         JSR C31114      ; Reset OAM, queue
         JSR C36A87      ; Load nonskin GFX
         JMP C33A87      ; Load skin visuals

; Clear cursor position restored from Lineup's Status menu...
C30138:; TDC             ; Clear A
       ; TAY             ; Clear Y
       ; STY $8E         ; Clear position
       ; RTS

; Invoke main menu
C3011A:  LDA #$04        ; C3/1A8A
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke shop menu
C30121:  JSR C33F99      ; Apply user font
         LDA #$24        ; C3/B466
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke Lineup menu
C3012B:  JSR C33F99      ; Apply user font
;        JSR C30138      ; Clear saved cursor
         LDA #$2C        ; C3/70E7
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke SwdTech naming menu (SFC)
C30149:; JSR C33F99      ; Apply user font
       ; LDA #$3F        ; C3/B437
       ; STA $26         ; Next: Bogus...
       ; BRA C301BA      ; Enter menu loop

; Invoke Colosseum menu
C30152:  JSR C33F99      ; Apply user font
;        STZ $79         ; Never read...
;        STZ $7A         ; Never read...
;        STZ $7B         ; Never read...
         LDA #$71        ; C3/ACAA
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke final battle lineup
C30166:  JSR C33F99      ; Apply user font
         LDA #$73        ; C3/A9F8
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke Load menu
C3016F:  LDA $307FF1     ; RNG index in SRAM
         INC A           ; RNG index +1
         STA $307FF1     ; Save changes
         JSL C3A424      ; Init joypad data
         JSR C37023      ; Test SRAM markers
         BCC C3019F      ; Abort if invalid
         LDA #$01        ; Song: The Prelude
         STA $1301       ; Set I/O port 1
         LDA #$10        ; APU command
         STA $1300       ; Set I/O port 0
         LDA #$80        ; Volume specs
         STA $1302       ; Set I/O port 2
         JSL $C50004     ; Play song
         LDA #$FF        ; New game: No
         STA $0205       ; Preset exit mode
         LDA #$20        ; C3/1D03
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Fork: Force new game
C3019F:  JSR C32A21      ; Reset play time
         LDA #$01        ; Save slot: 1
         STA $0224       ; Set last viewed
         STZ $021F       ; Game's file: None
         JSR C3E269      ; Next: Exit menu
         STZ $0205       ; Set new game mode
         BRA C301BA      ; Enter menu loop

; Invoke actor naming menu
C301B3:  JSR C33F99      ; Apply user font
         LDA #$5D        ; C3/652D
         STA $26         ; Next: Init menu

; Main loop for field menus
C301BA:  JSR C31412      ; Refresh screen
C301BD:  TDC             ; Clear A
         LDA $26         ; Menu command
         CMP #$FF        ; Exit to map?
         BEQ C301D8      ; Branch if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JSR (C301DB,X)  ; Handle menu cmd
         JSR C311B0      ; Handle anim queue
         JSR C3134D      ; Update screen/pad
         JSR C302DB      ; Check event timer
         BRA C301BD      ; Loop
C301D8:  STZ $43         ; Disable HDMA
         RTS

; Jump table for the above
C301DB:  dw C31D71       ; 00: Fade out screen
         dw C31D7E       ; 01: Fade in screen
         dw C31D8B       ; 02: Wait while menu fades in or out
         dw C31D94       ; 03: Exit main menu's portrait area
         dw C31A8A       ; 04: Initialize main menu
         dw C31DA4       ; 05: Sustain main menu
         dw C31DE8       ; 06: Target one actor in main menu
         dw C31AD6       ; 07: Initialize Item menu
         dw C31EF7       ; 08: Handle Item menu choice 1
         dw C31B5B       ; 09: Initialize Skills menu
         dw C31FF4       ; 0A: Sustain Skills menu
         dw C31C46       ; 0B: Initialize Status menu
         dw C321F5       ; 0C: Sustain Status menu
         dw C31C7D       ; 0D: Initialize Config menu
         dw C322C5       ; 0E: Sustain Config menu
         dw C3240C       ; 0F: Handle Order menu choice 1
         dw C32453       ; 10: Handle Order menu choice 2
         dw C324A9       ; 11: Switch members in Order menu
         dw C32537       ; 12: Wait while member changes row
         dw C31CA0       ; 13: Initialize Save menu
         dw C32540       ; 14: Sustain Save menu
         dw C31CE3       ; 15: Initialize save confirmation
         dw C3259D       ; 16: Sustain save confirmation
         dw C325F4       ; 17: Handle Item menu options
         dw C32741       ; 18: Sustain rare item menu
         dw C32779       ; 19: Handle Item menu choice 2
         dw C327E2       ; 1A: Sustain Magic menu
         dw C3288A       ; 1B: Sustain Lore menu
         dw C328AA       ; 1C: Sustain Dance menu
         dw C328BA       ; 1D: Sustain Rage menu
         dw C328D3       ; 1E: Handle esper selection
         dw C30000       ; 1F: Unused...
         dw C31D03       ; 20: Initialize Load menu
         dw C329C2       ; 21: Sustain Load menu
         dw C31D51       ; 22: Initialize load confirmation
         dw C32A2A       ; 23: Sustain load confirmation
         dw C3B466       ; 24: Initialize shop menu
         dw C3B49B       ; 25: Sustain main shop menu
         dw C3B4BD       ; 26: Handle buy item list
         dw C3B505       ; 27: Handle buy order menu
         dw C3B60E       ; 28: Return to Buy menu after delay
         dw C3B616       ; 29: Handle sell item list
         dw C3B676       ; 2A: Handle sell order menu
         dw C3B752       ; 2B: Return to Sell menu after delay
         dw C370E7       ; 2C: Initialize Lineup menu
         dw C37168       ; 2D: Handle Lineup menu choice 1
         dw C3720C       ; 2E: Handle Lineup menu choice 2
         dw C30000       ; 2F: Unused...
         dw C30000       ; 30: Unused...
         dw C30000       ; 31: Unused...
         dw C30000       ; 32: Unused...
         dw C32977       ; 33: Sustain Blitz menu
         dw C3293A       ; 34: Wait while showing who holds esper
         dw C31BB8       ; 35: Initialize Equip menu
         dw C39621       ; 36: Handle Equip menu options
         dw C31EB5       ; 37: Handle multitargeting in main menu
         dw C31C32       ; 38: Initialize party gear overview
         dw C32966       ; 39: Sustain party gear overview
         dw C32A65       ; 3A: Initialize spell usage menu
         dw C32AAE       ; 3B: Handle single-target spell
         dw C32D1C       ; 3C: Return to Magic menu
         dw C32D78       ; 3D: Handle multitarget spell
         dw C3298E       ; 3E: Sustain SwdTech menu
         dw C30000       ; 3F: SFC: Initialize SwdTech naming menu
         dw C30000       ; 40: SFC: Handle SwdTech naming choice 1
         dw C30000       ; 41: SFC: Handle SwdTech naming choice 2
         dw C3631D       ; 42: Initialize Lineup's Status menu
         dw C3633F       ; 43: Sustain Lineup's Status menu
         dw C30000       ; 44: Unused...
         dw C30000       ; 45: Unused...
         dw C30000       ; 46: Unused...
         dw C342C2       ; 47: Initialize Cmd.Set menu
         dw C342DF       ; 48: Handle Cmd.Set menu member selection
         dw C30000       ; 49: SFC: Initialize Button Settings menu
         dw C30000       ; 4A: SFC: Sustain Button Settings menu
         dw C346AD       ; 4B: Initialize Controller menu
         dw C346CA       ; 4C: Sustain Controller menu
         dw C358CE       ; 4D: Sustain esper data menu
         dw C30000       ; 4E: SFC: Scroll to SwdTech naming page 2
         dw C30000       ; 4F: SFC: Scroll to SwdTech naming page 1
         dw C33A00       ; 50: Scroll to Config page 2
         dw C33A21       ; 51: Scroll to Config page 1
         dw C31A0A       ; 52: Queue fade-in for save menu
         dw C319FB       ; 53: Queue fade-out for save menu
         dw C31A19       ; 54: Wait while save menu fades in or out
         dw C39884       ; 55: Handle selection of gear slot to fill
         dw C398CF       ; 56: Handle manual gear removal
         dw C3990F       ; 57: Handle gear browsing
         dw C39E4B       ; 58: Initialize Relic menu
         dw C39EB8       ; 59: Handle Relic menu options
         dw C39FFD       ; 5A: Handle selection of relic slot to fill
         dw C3A097       ; 5B: Handle relic browsing
         dw C3A10A       ; 5C: Handle relic removal
         dw C3652D       ; 5D: Initialize actor naming menu
         dw C389E6       ; 5E: Sustain shifted gear data menu
         dw C3656C       ; 5F: Sustain actor naming menu
         dw C30000       ; 60: SFC: Scroll to actor naming page 2
         dw C30000       ; 61: SFC: Scroll to actor naming page 1
         dw C34338       ; 62: Handle Cmd.Set menu command choice 1
         dw C34376       ; 63: Handle Cmd.Set menu command choice 2
         dw C38983       ; 64: Sustain non-shifted gear data menu
         dw C336E7       ; 65: Shift screen
         dw C379FF       ; 66: Queue fade-in for Lineup menu
         dw C379F0       ; 67: Queue fade-out for Lineup menu
         dw C37A0E       ; 68: Wait while Lineup menu fades in or out
         dw C37A87       ; 69: Erase warning in Lineup menu after delay
         dw C363A7       ; 6A: Sustain shifted Status menu
         dw C30000       ; 6B: Unused...
         dw C39FB1       ; 6C: Handle delayed fade-out for Reequip
         dw C31C1A       ; 6D: Open Equip menu after optimizing gear
         dw C31C26       ; 6E: Open Equip menu after removing all gear
         dw C38A84       ; 6F: Initialize item usage menu
         dw C38A96       ; 70: Sustain item usage menu
         dw C3ACAA       ; 71: Initialize Colosseum item menu
         dw C3ACDC       ; 72: Sustain Colosseum item menu
         dw C3A9F8       ; 73: Initialize final battle lineup
         dw C3AA25       ; 74: Sustain final battle lineup
         dw C3ADB7       ; 75: Initialize Colosseum matchup menu
         dw C3AE0F       ; 76: Sustain Colosseum matchup menu
         dw C31B35       ; 77: Return from item usage menu
         dw C30000       ; 78: Unused...
         dw C39E7D       ; 79: Swap actor in Relic menu, retain Equip mode
         dw C39E8B       ; 7A: Swap actor in Relic menu, retain Remove mode
         dw C30000       ; 7B: Unused...
         dw C30000       ; 7C: Unused...
         dw C37131       ; 7D: Return to Lineup menu from Status menu
         dw C31BE5       ; 7E: Swap actor in Equip menu, retain Equip mode
         dw C31BF3       ; 7F: Swap actor in Equip menu, retain Remove mode

; Set to exit menu if event countdown timer expired
C302DB:  LDA $B4         ; Already handled?
         BNE C302F8      ; Exit if so
         LDA $1188       ; Timer 0 flags
         BIT #$20        ; Abort if expired?
         BEQ C302F8      ; Exit if not
         LDY $1189       ; Timer expired?
         BNE C302F8      ; Exit if not
         JSR fdexit      ; Queue menu exit
         LDA #$05        ; Origin: Timer
         STA $0205       ; Set exit reason
         STA $B4         ; Disable this fn
C302F8:  RTS

; Load text string into tilemap
C302F9:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
C302FD:  STA $E9         ; Set src HB
         STY $E7         ; Set src LBs
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set dst LBs
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDY #$0002      ; Src index
         LDX $00         ; Dst index: 0
C30312:  LDA [$E7],Y     ; Text character
         BEQ C302F8      ; Exit if <end>
         PHY             ; Save src index
         TXY             ; Dst index
         STA [$EB],Y     ; Add char to map
         INX             ; Map index +1
         TXY             ; Move it to Y
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; Dst index +1
         PLY             ; Src index
         INY             ; Src index +1
         BRA C30312      ; Load next char

; Load and adjust window tile numbers, define attributes
C30326:  STY $E7         ; Save attributes
         LDX #$0036      ; Tile index
C3032C:  REP #$21        ; 16-bit A; C-
         LDA.L C3044E,X  ; Tile number
         ADC $E7         ; Add attributes
         STA $7E9F19,X   ; Save in RAM
         DEX             ; Index -1
         DEX             ; Index -1
         BPL C3032C      ; Loop till < 0
         SEP #$20        ; 8-bit A
         RTS

; Prepare to and draw a menu window
C30341:  LDA #$C3        ; Bank: C3
C30343:  STA $E9         ; Set src HB
C30345:  STX $E7         ; Set src LBs
         LDY #$0002      ; Src index
         LDA [$E7],Y     ; Inner width
         STA $EF         ; Memorize it
         STZ $F0         ; Clear HB
         INY             ; Index +1
         LDA [$E7],Y     ; Inner height
         STA $F1         ; Memorize it
         STZ $F2         ; Clear HB
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set position
         JSR C30375      ; Draw window
         SEP #$20        ; 8-bit A
         RTS

; Draw a menu window
C30375:  JSR C303A3      ; Draw top row
         LDX $00         ; Inner row: 1st
         LDY #$0040      ; Skipped rows: 1
         STY $F3         ; Init map index
C3037F:  PHX             ; Save row number
         TXA             ; Move it to A
         AND #$0003      ; Get pattern row
         ASL A           ; Double it
         TAX             ; Index it
         JSR (C3039B,X)  ; Draw inner row
         LDA $F3         ; Tilemap index
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $F3         ; Save changes
         TAY             ; Index it
         PLX             ; Row number
         INX             ; Row number +1
         CPX $F1         ; At last row?
         BNE C3037F      ; Loop if not
         BRA C303BB      ; Draw last row

; Jump table for the above
C3039B:  dw C303D1       ; Pattern row 1 of 4
         dw C303DB       ; Pattern row 2 of 4
         dw C303E8       ; Pattern row 3 of 4
         dw C303F5       ; Pattern row 4 of 4

; Draw window's upper row
C303A3:  LDY $00         ; Map index: 0
         JSR C30408      ; Define pattern
         LDA $7E9F49     ; NW corner tile
         STA $E3         ; Set first tile
         LDA $7E9F4B     ; NE corner tile
         STA $E5         ; Set final tile
         LDX #$0020      ; Base tile index
         BRA C30428      ; Draw top row

; Draw window's lower row
C303BB:  JSR C30408      ; Define pattern
         LDA $7E9F4D     ; SW corner tile
         STA $E3         ; Set first tile
         LDA $7E9F4F     ; SE corner tile
         STA $E5         ; Set final tile
         LDX #$0024      ; Base tile index
         BRA C30428      ; Draw bottom row

; Draw inner window row, pattern part 1 of 4
C303D1:  JSR C30402      ; Define pattern
         JSR C3040E      ; Get side tiles
         LDX $00         ; Base tile index
         BRA C30428      ; Draw inner row

; Draw inner window row, pattern part 2 of 4
C303DB:  JSR C30402      ; Define pattern
         JSR C3041B      ; Get side tiles
         LDX #$0008      ; Base tile index
         BRA C30428      ; Draw inner row

; Draw inner window row, pattern part 3 of 4
C303E8:  JSR C30402      ; Define pattern
         JSR C3040E      ; Get side tiles
         LDX #$0010      ; Base tile index
         BRA C30428      ; Draw inner row

; Draw inner window row, pattern part 4 of 4
C303F5:  JSR C30402      ; Define pattern
         JSR C3041B      ; Get side tiles
         LDX #$0018      ; Base tile index
;        BRA C30428      ; Draw inner row

; Draw a row of window tiles
C30428:  STX $E0         ; Set base index
         LDX $00         ; Inner col: 1st
         LDA $E3         ; Leftmost tile
         STA [$EB],Y     ; Add to tilemap
         INY             ; Map index +1
         INY             ; Map index +1
C30430:  PHX             ; Save column
         TXA             ; Move it to A
         AND $F5         ; Stay in pattern
         ASL A           ; Double it
;        CLC             ; ...
         ADC $E0         ; Add base index
         TAX             ; Index sum
         LDA $7E9F19,X   ; Inner tile
         PLX             ; Column number
         CPX $EF         ; At last one?
         BEQ C30449      ; Branch if so
         STA [$EB],Y     ; Add tile to map
         INY             ; Map index +1
         INY             ; Map index +1
         INX             ; Column +1
         BRA C30430      ; Do next tile
C30449:  LDA $E5         ; Rightmost tile
         STA [$EB],Y     ; Add to tilemap
         RTS

; Set pattern width for inner window tiles
C30402:  LDX #$0003      ; Tiles: 4
         STX $F5         ; Set pattern width
         RTS

; Set pattern width for top or bottom window border
C30408:  LDX #$0001      ; Tiles: 2
         STX $F5         ; Set pattern width
         RTS

; Get window side tiles for odd-numbered pattern row
C3040E:  LDA $7E9F41     ; Left border A
         STA $E3         ; Set first tile
         LDA $7E9F43     ; Right border A
         STA $E5         ; Set final tile
         RTS

; Get window side tiles for even-numbered pattern row
C3041B:  LDA $7E9F45     ; Left border B
         STA $E3         ; Set first tile
         LDA $7E9F47     ; Right border B
         STA $E5         ; Set final tile
         RTS

; Window tile numbers
C3044E:  dw $0180        ; Inner part 1,1
         dw $0181        ; Inner part 1,2
         dw $0182        ; Inner part 1,3
         dw $0183        ; Inner part 1,4
         dw $0184        ; Inner part 2,1
         dw $0185        ; Inner part 2,2
         dw $0186        ; Inner part 2,3
         dw $0187        ; Inner part 2,4
         dw $0188        ; Inner part 3,1
         dw $0189        ; Inner part 3,2
         dw $018A        ; Inner part 3,3
         dw $018B        ; Inner part 3,4
         dw $018C        ; Inner part 4,1
         dw $018D        ; Inner part 4,2
         dw $018E        ; Inner part 4,3
         dw $018F        ; Inner part 4,4
         dw $0191        ; Upper border A
         dw $0192        ; Upper border B
         dw $0199        ; Lower border A
         dw $019A        ; Lower border B
         dw $0194        ; Left border A
         dw $0195        ; Right border A
         dw $0196        ; Left border B
         dw $0197        ; Right border B
         dw $0190        ; NW corner
         dw $0193        ; NE corner
         dw $0198        ; SW corner
         dw $019B        ; SE corner

; Draw 3 digits (16-bit number)
C30486:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY #$0002      ; Skipped: 2
         BRA C304C7      ; Draw text

; Draw 4 digits
C30490:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C304C7      ; Draw text

; Draw 5 digits
C3049A:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
         BRA C304C7      ; Draw text

; Draw 8 digits
C304A3:  LDY #$0008      ; Digits: 8
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
         BRA C304C7      ; Draw text

; Draw 7 digits
C304AC:  LDY #$0008      ; Digits: 8
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C304C7      ; Draw text

; Draw 2 digits
C304B6:  LDY #$0003      ; Digits: 3
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C304C7      ; Draw text

; Draw 3 digits (8-bit number)
C304C0:  LDY #$0003      ; Digits: 3
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
C304C7:  STX $EB         ; Set dst LBs
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         TYX             ; Digit index
         LDY $00         ; Map index: 0
C304D0:  LDA $F7,X       ; Digit char
         STA [$EB],Y     ; Add to tilemap
         INY             ; Map index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INY             ; Map index +1
         INX             ; Digit index +1
         CPX $E0         ; More digits?
         BNE C304D0      ; Loop if so
         RTS

; Convert 8-bit number into text, blank leading zeroes
C304E0:  JSR C304F9      ; Turn into text
         LDY #$0002      ; Digits: 2
         BRA C3056_      ; Blank zeroes

; Convert 8-bit number into text, retain leading zeroes
C304F9:  STA $E0         ; Save number
         LDA #$03        ; Digits: 3
         STA $E4         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C30502:  STZ $E1         ; Digit: 0
         LDA.L C3052B,X  ; Power of 10
         INX             ; ROM index +1
         STA $E3         ; Save power
C3050B:  LDA $E0         ; Revised number
         SEC             ; Prepare SBC
         SBC $E3         ; Deduct power
         BCC C30518      ; Branch if < 0
         STA $E0         ; Save changes
         INC $E1         ; Digit +1
         BRA C3050B      ; Loop
C30518:  LDA $E1         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; Point to next
         DEC $E4         ; One less left
         BNE C30502      ; Loop till last
         RTS

; Powers of ten for the above
C3052B:  db $64          ; 100
         db $0A          ; 10
         db $01          ; 1

; Convert 16-bit number into text, blank leading zeroes
C3052E:  LDA #$05        ; Digits: 5
         STA $E0         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C30535:  REP #$20        ; 16-bit A
         LDA.L C30578,X  ; Power of 10
         INX             ; ROM index +1
         INX             ; ROM index +1
         STA $ED         ; Save power
         STZ $EB         ; Digit: 0
C30541:  SEC             ; Prepare SBC
         LDA $F3         ; Revised number
         SBC $ED         ; Deduct power
         BCC C3054E      ; Branch if < 0
         STA $F3         ; Save changes
         INC $EB         ; Digit +1
         BRA C30541      ; Loop

; Fork: Convert digit into text
C3054E:  SEP #$20        ; 8-bit A
         LDA $EB         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; RAM index +1
         DEC $E0         ; One less digit
         BNE C30535      ; Loop till last

; Fork: Blank leading zeroes
C30562:  LDY #$0004      ; Digits: 4
C3056_:  LDX $00         ; Index: 0
C30567:  LDA $F7,X       ; Digit char
         CMP.B #!num0    ; Zero?
         BNE C30583      ; Exit if not
         LDA #$FF        ; Space char
         STA $F7,X       ; Replace digit
         INX             ; Point to next
         DEY             ; One less left
         BNE C30567      ; Loop till last
C30583:  RTS

; Convert 24-bit number into text, blank leading zeroes
C30582:  STZ $F4         ; Number HB: 0
         LDA #$08        ; Digits: 8
         STA $E0         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C3058B:  REP #$20        ; 16-bit A
         STZ $EB         ; Digit: 0
C3058F:  SEC             ; Prepare SBC
         LDA $F1         ; Number LBs
         SBC.L C305DE,X  ; Deduct power's
         STA $F1         ; Save changes
         LDA $F3         ; Number HBs
         SBC.L C305EE,X  ; Deduct power's
         BCC C305A6      ; Branch if < 0
         STA $F3         ; Save changes
         INC $EB         ; Digit +1
         BRA C3058F      ; Loop

; Fork: Cancel subtraction and convert digit
C305A6:  LDA $F1         ; Number LBs
;        CLC             ; Prepare ADC
         ADC.L C305DE,X  ; Reverse SBC
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         LDA $EB         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; RAM index +1
         INX             ; ROM index +1
         INX             ; ROM index +1
         DEC $E0         ; One less digit
         BNE C3058B      ; Loop till last

; Fork: Blank leading zeroes
C305C8:  LDY #$0007      ; Digits: 7
         BRA C3056_      ; Blank zeroes

; Powers of ten, low bytes
C305DE:  dw $9680        ; 10000000
         dw $4240        ; 1000000
         dw $86A0        ; 100000
C30578:  dw $2710        ; 10000
         dw $03E8        ; 1000
         dw $0064        ; 100
         dw $000A        ; 10
         dw $0001        ; 1

; Powers of ten, high bytes
C305EE:  dw $0098        ; 10000000
         dw $000F        ; 1000000
         dw $0001        ; 100000
         dw $0000        ; 10000
         dw $0000        ; 1000
         dw $0000        ; 100
         dw $0000        ; 10
         dw $0000        ; 1

; Load navigation parameters for menu area
C305FE:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
C30600:  STA $ED         ; Set src HB
         STY $EB         ; Set src LBs
         LDY $00         ; Index: 0
         LDA [$EB],Y     ; Wrap flags
         STA $59         ; Save in RAM
         INY             ; Index +1
         REP #$20        ; 16-bit A
         STZ $51         ; See C3/06D5...
         LDA [$EB],Y     ; Initial spot
         STA $4D         ; Set cursor's
         INY             ; Index +1
         INY             ; Index +1
         LDA [$EB],Y     ; Rows, columns
         STA $53         ; Set boundaries
         STZ $4F         ; List col/row: 1
         SEP #$20        ; 8-bit A
         RTS

; Target party's leader
C3061E:  TDC             ; Clear A
         TAY             ; Member: 1st
C30620:  TYA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $85,X       ; Empty slot?
         BNE C3062F      ; Exit if not
         INC $4E         ; Cursor row +1
         INY             ; Member slot +1
         CPY #$0004      ; Done all 4?
         BNE C30620      ; Loop if not
C3062F:  RTS

; Set address to table of cursor coordinates
C30630:  STY $E7         ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         RTS

; Position cursor in party area of Lineup menu
C30637:  JSR C30630      ; Set source
         JSR C30650      ; Set list slot
         BRA C306C5      ; Set coords

; Position cursor in unscrollable area
C30640:  JSR C30630      ; Set source
C30643:  JSR C30677      ; Set list slot
         BRA C306C5      ; Set coords

; Position cursor in scrollable list
C30648:  JSR C30630      ; Set source
         JSR C3069E      ; Set list slot
         BRA C306C5      ; Set coords

; Set cursor's slot position in party area of Lineup menu
C30650:  LDA $54         ; Row count
         XBA             ; Put in B
         LDA $4D         ; Cursor column
         JSR mul8        ; Multiply them
;        CLC             ; Prepare ADC
         ADC $4E         ; Add cursor row
         STA $4B         ; Set cursor slot
         RTS

; Set cursor's slot position in unscrollable area
C30677:  LDA $53         ; Column count
         XBA             ; Put in B
         LDA $4E         ; Cursor row
         JSR mul8        ; Multiply them
;        CLC             ; Prepare ADC
         ADC $4D         ; Add cursor col
         STA $4B         ; Set cursor slot
         RTS

; Set cursor's slot position in scrollable list
C3069E:  LDA $53         ; Column count
         XBA             ; Put in B
         LDA $50         ; List row
         JSR mul8        ; Row x count
;        CLC             ; Prepare ADC
         ADC $4F         ; Add list column
         STA $4B         ; Set cursor slot
         RTS

; Set cursor's position in pixels
C306C5:  LDA $53         ; Column count
         DEC A           ; Adjust value
         CMP $4D         ; In range now?
         BCS C306DD      ; Branch if so

; Fork: Invalid column (unused)
C306D1:  SEC             ; Prepare SBC
         SBC $51         ; Minus 0...
         STA $E0         ; Use col qty -1
         STA $E2         ; Use last column
         BRA C306E5      ; Validate row

; Fork: Valid column
C306DD:  LDA $53         ; Column count
         STA $E0         ; Memorize it
         LDA $4D         ; Cursor column
         STA $E2         ; Memorize it

; Fork: Validate row
C306E5:  LDA $54         ; Number of rows
         DEC A           ; Adjust value
         CMP $4E         ; In range now?
         BCS C306F6      ; Branch if so

; Fork: Invalid row (unused)
C306EC:  SEC             ; Prepare SBC
         SBC $52         ; Minus 0...
;        STA $E1         ; Force last row
         BRA C306F8      ; Skip a line

; Fork: Valid row
C306F6:  LDA $4E         ; Cursor row
C306F8:  STA $E1         ; Memorize it
         LDA $E0         ; Column count
         XBA             ; Put in B
         LDA $E1         ; Cursor row
         JSR mul8        ; Row x count
         ADC $E2         ; Add column
         ASL A           ; Double it
;        PHA             ; Push position
;        TDC             ; Clear A
;        PLA             ; Pull position
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$E7],Y     ; Coordinates
         STA $55         ; Set cursor's
         SEP #$20        ; 8-bit A
C3072C:  RTS

; Handle D-Pad for unscrollable list
C3072D:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C30750      ; Branch if not
         LDA $4E         ; On top row?
         BNE C30748      ; Go up if not
         LDA $59         ; Wrap flags
         LSR A           ; No V-Wrap?
         BCS C3072C      ; Exit if so
         LDA $54         ; Bottom row
         DEC A           ; Adjust value
         STA $4E         ; Set cursor row
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor up
C30748:  DEC $4E         ; Cursor row -1
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle down
C30750:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C30773      ; Branch if not
         LDA $54         ; Bottom row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BNE C3076B      ; Go down if not
         LDA $59         ; Wrap flags
         LSR A           ; No V-Wrap?
         BCS C3072C      ; Exit if so
         STZ $4E         ; Cursor row: 1
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor down
C3076B:  INC $4E         ; Cursor row +1
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle left
C30773:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C30792      ; Branch if not
         LDA $4D         ; On first column?
         BNE C3078B      ; Go left if not
         LDA $59         ; H-Wrap disabled?
         BMI C3072C      ; Exit if so
         LDA $53         ; Last column
         DEC A           ; Adjust value
         STA $4D         ; Set cursor column
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor left
C3078B:  DEC $4D         ; Cursor column -1
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle right
C30792:  LSR A           ; Pushing right?
         BCC C3072C      ; Exit if not
         LDA $53         ; Last column
         DEC A           ; Adjust value
         CMP $4D         ; Cursor's there?
         BNE C307AA      ; Go right if not
         LDA $59         ; H-Wrap disabled?
         BMI C3072C      ; Exit if so
         STZ $4D         ; Cursor column: 1
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor right
C307AA:  INC $4D         ; Cursor column +1
         JMP C30EA3      ; Sound: Cursor

; Queue movable cursor's OAM function
C307B0:  LDY #C307B8     ; C3/07B8
         JMP qanim1      ; Queue OAM fn

; Update movable cursor's sprite
C307B8:  BNE C307DC      ; If mode 1

; Mode 0: Initialize cursor
C307C0:  LDY #C3088D     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         JSR C3EA6C      ; Follow BG1: Y

; Mode 1: Sustain cursor
C307DC:  LDA $46         ; Menu flags
         AND #$06        ; Remove cursors?
         BEQ C307FD      ; Delete if so
         LDA $45         ; Menu flags
         BIT #$04        ; Hide cursor?
         BEQ C307FB      ; Exit if so
         LDY $55         ; Cursor pos
         JSR objpos      ; Set sprite's
         JSR C31221      ; Define OAM
C307FB:  SEC             ; Set to requeue
         RTS             ; Exit
C307FD:  CLC             ; Set to dequeue
         RTS

; Update blinking cursor marking prior choice
C307FF:  BNE C3082B      ; If mode 1

; Mode 0: Initialize cursor
C3080B:  LDA #$01        ; Blinkers V1: On
         TSB $46         ; Set menu flag
         LDY #C30896     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31206      ; Set pose timer
         JSR C3EA6C      ; Follow BG1: Y
         INC $3649,X     ; Mode +1

; Mode 1: Sustain cursor
C3082B:  LDA $46         ; Menu flags
         LSR A           ; Remove blinkers?
         BCC C30865      ; Delete if so
         REP #$21        ; 16-bit A; C-
         LDA $41         ; List V-Speed
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         ADC $344A,X     ; Add cursor's Y
         STA $344A,X     ; Set cursor's Y
         SEP #$20        ; 8-bit A
         LDA $46         ; Menu flags
         AND #$C0        ; Scrollable list?
         BEQ C30860      ; Display if not

; Fork: Item menu
C3084A:  LDA $28         ; Blinker's slot
         STA $E1         ; Memorize it
         INC A           ; Get next slot
         STA $E0         ; Memorize it
         LDA $4A         ; Top onscreen slot
         CLC             ; Prepare ADC
         ADC #$09        ; Get bottom slot
         CMP $E1         ; Blinker's below?
         BCC C30863      ; Blank if so
         LDA $4A         ; Top onscreen slot
         CMP $E0         ; Blinker's above?
         BCS C30863      ; Blank if so
C30860:  JSR C31221      ; Define OAM
C30863:  SEC             ; Set to requeue
         RTS             ; Exit
C30865:  CLC             ; Set to dequeue
         RTS

; Create a blinking cursor by every portrait
C3089F:  TDC             ; Clear A
         TAX             ; Member: 1st
C308A1:  LDA $85,X       ; Nobody here?
         BEQ C308C9      ; Skip if so
         PHX             ; Save index
         LDY #C308D1     ; C3/08D1
         JSR qanim1      ; Queue OAM fn
         PLY             ; Member index
         LDA $0085,Y     ; X position
         STA $7E33CA,X   ; Set cursor's
         LDA $0086,Y     ; Y position
         STA $7E344A,X   ; Set cursor's
         TYX             ; Char index
C308C9:  INX             ; Char index +1
         INX             ; Char index +1
         CPX #$0008      ; Done 4 chars?
         BNE C308A1      ; Loop if not
         RTS

; Update blinking cursor not marking a prior choice
C308D1:  BNE C308F9      ; If mode 1

; Mode 0: Initialize cursor
C308D9:  LDA #$08        ; Blinkers V2: On
         TSB $46         ; Set menu flag
         LDY #C30896     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         JSR C3EA6C      ; Follow BG1: Y

; Mode 1: Sustain cursor
C308F9:  LDA $46         ; Menu flags
         BIT #$08        ; Remove blinkers?
         BEQ C30865      ; Delete if so
         JMP oamsec      ; Set OAM; requeue

; Update scrollbar animation index
C30908:  LDA #$C0        ; Flashing: 2-ways
         TSB $46         ; Initialize index
         LDA $4A         ; At top of list?
         BNE C30914      ; Branch if not
         LDA #$40        ; Flashing: Down
         TRB $46         ; Update index
C30914:  LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BNE C3091E      ; Exit if not
         LDA #$80        ; Flashing: Up
         TRB $46         ; Update index
C3091E:  RTS

; Create a scrollbar on right side of screen
C3091F:  PHA             ; Save Y pos
         LDA #$E8        ; X: 232
         BRA C3093_      ; Skip 2 lines

; Create a scrollbar in middle of screen
C30933:  PHA             ; Save Y pos
         LDA #$78        ; X: 120
C3093_:  PHA             ; Save X pos
         PHY             ; Save V-Speed
         LDY #C30947     ; C3/0947
         JSR qanim3      ; Queue OAM fn
         REP #$20        ; 16-bit A
         PLA             ; V-Speed
         STA $7E354A,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         PLA             ; X position
         STA $7E33CA,X   ; Set sprite's
         PLA             ; Y position
         STA $7E34CA,X   ; Set sprite's
         RTS

; Update scrollbar
C30947:  BNE C3096A      ; If mode 1

; Mode 0: Initialize scrollbar
C3094F:  LDY #C309E3     ; C3/09E3
         JSR anm_c3      ; Init anim ptr
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         LDA #$C0        ; Flash: Both ways
         TSB $46         ; Init anim index

; Mode 1: Sustain scrollbar
C3096A:  LDA $46         ; Menu flags
         AND #$C0        ; Hide scrollbar?
         BEQ C309D9      ; Delete if so
         JSR C30908      ; Set anim index
         LDY $354A,X     ; V-Speed
         LDA $4A         ; Scroll position
         JSR mul16       ; Speed x position
         LDX $2D         ; Queue index
         TDC             ; Y modifier: 0
         LDY $49         ; Scroll position
         BPL C309AA      ; Branch if < 128
         LDA #$70        ; Y modifier: 112
C309AA:  CLC             ; Prepare ADC
         ADC $002135     ; Add product MB
         ADC $34CA,X     ; Add base Y
         STA $344A,X     ; Set bar's Y
         TDC             ; Clear A
         LDA $46         ; Menu flags
         AND #$C0        ; Anim index
         LSR A           ; Put in b5-b6
         LSR A           ; Put in b4-b5
         LSR A           ; Put in b3-b4
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         TXY             ; Queue index
         TAX             ; Anim index
         REP #$20        ; 16-bit A
         LDA.L C309DB-2,X; Anim pointer
         STA $32C9,Y     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue
C309D9:  CLC             ; Set to dequeue
         RTS

; Create portrait for member 1
C30A22:  LDA #$15        ; Base Y: 21
         LDX $00         ; Member slot: 1
         BRA C30AA_      ; Create sprite

; Create portrait for member 2
C30A4B:  LDA #$45        ; Base Y: 69
         LDX #$0001      ; Member slot: 2
         BRA C30AA_      ; Create sprite

; Create portrait for member 3
C30A76:  LDA #$75        ; Base Y: 117
         LDX #$0002      ; Member slot: 3
         BRA C30AA_      ; Create sprite

; Create portrait for member 4
C30AA1:  LDA #$A5        ; Base Y: 165
         LDX #$0003      ; Member slot: 4
C30AA_:  PHA             ; Save Y pos
         PHX             ; Save slot
         LDY #C30B12     ; C3/0B12
         JSR qanim3      ; Queue OAM fn
         JSR db7e        ; Set DB to 7E
         PLY             ; Member slot
         TXA             ; Queue index
         STA $0060,Y     ; Set sprite's
         JSR C30AF1      ; Set base X loc
         JSR C30ACC      ; Load anim ptr
         PLA             ; Base Y pos
         STA $344A,X     ; Set sprite's
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 00
         RTS

; Load pointer to animation table for portrait
C30ACC:  LDA $0075,Y     ; Party info
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
C30AC_:  PHX             ; Save queue index
         TAX             ; Index face slot
         REP #$20        ; 16-bit A
         LDA.L C30AE9,X  ; Anim table ptr
         TAY             ; Put in Y
         PLX             ; Queue index
         JMP anm_c3      ; Set anim ptr

; Set portrait's base X position based on actor's row
C30AF1:  LDA #$02        ; Portrait bit
         BIT $45         ; Ignore row?
         BNE C30AFF      ; Branch if so
         LDA $0075,Y     ; Party info
         BIT #$20        ; In back row?
         BEQ C30B06      ; Branch if not
C30AFF:  LDA #$1A        ; Base X: 26
         BRA C30B0B      ; Skip a line
C30B06:  LDA #$0E        ; Base X: 15
C30B0B:  STA $33CA,X     ; Set sprite's X
         RTS

; Update actor portrait
C30B12:  TAX             ; Index mode
         JMP (C30B16,X)  ; Handle mode

; Jump table for the above
C30B16:  dw C30B20       ; Initialize data
         dw C30B2A       ; Sustain portrait
         dw C30B38       ; Set to shift right
         dw C30B4C       ; Set to shift left
         dw C30B5E       ; Shift left or right

; Mode 0: Initialize data
C30B20:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         JSR C3EA6C      ; Follow BG1: Y
         JSR C31206      ; Set pose timer

; Mode 1: Sustain portrait
C30B2A:  LDX $2D         ; Queue index
         LDA $35C9,X     ; Hide portrait?
         BMI C30B36      ; Delete if so
         JMP oamsec      ; Set OAM; requeue
C30B36:  CLC             ; Set to dequeue
         RTS

; Mode 2: Set to shift right
C30B38:  LDA #$01        ; H-Speed: 1
;        LDX $2D         ; Queue index
;        STA $34CA,X     ; Set H-Speed
;        LDA #$0C        ; Frames: 12
;        STA $3349,X     ; Set shift timer
         BRA C30B4_      ; Shift once

; Mode 3: Set to shift left
C30B4C:  LDA #$FF        ; H-Speed: -1
C30B4_:  LDX $2D         ; Queue index
         STA $34CA,X     ; Set H-Speed
         LDA #$0C        ; Frames: 12
         STA $3349,X     ; Set shift timer

; Mode 4: Shift left or right
C30B5E:  LDX $2D         ; Queue index
         LDA #$04        ; Mode: 4
         STA $3649,X     ; Set sprite's
         LDA $3349,X     ; Timer expired?
         BEQ C30B80      ; Freeze if so
         LDA $34CA,X     ; H-Speed
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add base X
         STA $33CA,X     ; Set sprite's
         DEC $3349,X     ; Timer -1
         JMP oamsec      ; Set OAM; requeue

; Fork: Set to stop moving
C30B80:  LDA #$01        ; Mode: 1
         STA $3649,X     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue

; Draw member's level, HP, and MP
C30C6C:  STX $EF         ; Pos tbl ptr LBs
         LDA #$C3        ; Bank: C3
         STA $F1         ; Set ptr HB
         LDX $67         ; Actor address
         LDA $08,X       ; Level
         JSR C304E0      ; Turn into text
         REP #$20        ; 16-bit A
         LDA [$EF]       ; Tilemap ptr
         TAX             ; Move it to X
         JSR C304B6      ; Draw level
         LDY $67         ; Actor address
         LDX $0B,Y       ; Max HP
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         JSR C3052E      ; Turn into text
         LDY #$0004      ; Map ptr index
         JSR C30D21      ; Draw max HP
         LDY $67         ; Actor's address
         JSR C32B9A      ; Truncate HP
         LDX $09,Y       ; Current HP
         STX $F3         ; Memorize it
         JSR C3052E      ; Turn into text
         LDY #$0002      ; Map ptr index
         JSR C30D21      ; Draw HP
         JSR C30D2B      ; Can use magic?
         BCC C30CEF      ; Hide MP if not
         LDY $67         ; Actor address
         LDX $0F,Y       ; Max MP
         JSR C30D65      ; Add gear bonus
         JSR C30D9F      ; Cap at 999
         JSR C3052E      ; Turn into text
         LDY #$0008      ; Map ptr index
         JSR C30D21      ; Draw max MP
         LDY $67         ; Actor address
         JSR C32BBC      ; Truncate MP
         LDX $0D,Y       ; Current MP
         STX $F3         ; Memorize it
         JSR C3052E      ; Turn into text
         LDY #$0006      ; Map ptr index
         BRA C30D21      ; Draw MP

; Fork: Hide MP
C30CEF:  REP #$20        ; 16-bit A
         LDY #$0006      ; Point to MP ptr
         LDA [$EF],Y     ; Tilemap ptr
         SEC             ; Prepare SBC
         SBC #$0006      ; Point to "MP"
         STA $7E9E89     ; Set position
         LDY #$000C      ; Spaces: 12
         JMP spacedr     ; Draw 12 spaces

; Draw member's current or max HP or MP
C30D21:  REP #$20        ; 16-bit A
         LDA [$EF],Y     ; Tilemap ptr
         TAX             ; Move it to X
         JMP C30490      ; Draw 4 digits

; Determine whether actor can use magic
C30D2B:  LDX $1A69       ; Espers LBs
         BNE C30D63      ; OK if got any
         LDX $1A6B       ; Espers HBs
         BNE C30D63      ; OK if got any
         LDY $67         ; Actor's address
         JSR gogo2       ; Actor = Gogo?
         BEQ C30D63      ; Allow if so
         BCS C30D61      ; Deny Umaro/guest
         XBA             ; Put actor in B
         LDA #$36        ; Spell list size
         JSR mul8        ; Actor x size
         TAX             ; Index product
         LDY #$0036      ; Spells left: 54
C30D56:  LDA $1A6E,X     ; Spell mastery
         INC A           ; Fully learned?
         BEQ C30D63      ; Allow if so
         INX             ; Point to next
         DEY             ; One less left
         BNE C30D56      ; Loop till last
C30D61:  CLC             ; Access: No
         RTS             ; Exit
C30D63:  SEC             ; Access: Yes
         RTS

; Determine max HP or MP with gear bonus
C30D65:  REP #$21        ; 16-bit A; C-
         TXA             ; Max HP or MP
         AND #$3FFF      ; Clear flags
         STA $E7         ; Memorize value
         TXA             ; Max HP or MP
         AND #$C000      ; Get bonus flags
         ROL A           ; Put in b7 & C
         ROL A           ; Put in C & b0
         ROL A           ; Put in b0-b1
         ROL A           ; Put in b1-b2
         TAX             ; Index them
         LDA $E7         ; Max HP or MP
         JMP (C30D7E,X)  ; Apply bonus

; Jump table for the above
C30D7E:  dw C30D86       ; No bonus
         dw C30D88       ; HP or MP + 25%
         dw C30D89       ; HP or MP + 50%
         dw C30D87       ; HP or MP + 12.5%

; Boost max HP or MP based on entry point
C30D86:  TDC             ; Clear bonus
C30D87:  LSR A           ; Halve bonus
C30D88:  LSR A           ; Halve bonus
C30D89:  LSR A           ; Halve bonus
         CLC             ; Prepare ADC
         ADC $E7         ; Add max value
         STA $F3         ; Memorize sum
         SEP #$20        ; 8-bit A
         RTS

; Enforce HP cap
C30D92:  LDX $F3         ; Max HP
         CPX #$2710      ; Under 10000?
         BCC C30D9E      ; Exit if so
         LDX #$270F      ; Enforce 9999
         STX $F3         ; Save changes
C30D9E:  RTS

; Enforce MP cap
C30D9F:  LDX $F3         ; Max MP
         CPX #$03E8      ; Under 1000?
         BCC C30DAB      ; Exit if so
         LDX #$03E7      ; Enforce 999
         STX $F3         ; Save changes
C30DAB:  RTS

; Interchange cursor memory for swapped members
C30DBA:  TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         ASL A           ; Double it
         TAX             ; Index it
         LDA $28         ; Chosen slot A
         ASL A           ; Double it
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA $0236,X     ; B's Skills pos
         PHA             ; Memorize it
         LDA $0236,Y     ; A's Skills pos
         STA $0236,X     ; Set as B's
         PLA             ; B's Skills pos
         STA $0236,Y     ; Set as A's
         LDA $023E,X     ; B's Magic pos
         PHA             ; Memorize it
         LDA $023E,Y     ; A's Magic pos
         STA $023E,X     ; Set as B's
         PLA             ; B's Magic pos
         STA $023E,Y     ; Set as A's
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $28         ; Chosen slot A
         TAY             ; Index it
         LDA $0246,X     ; B's Magic bar
         PHA             ; Memorize pos
         LDA $0246,Y     ; A's Magic bar
         STA $0246,X     ; Set as B's
         PLA             ; B's Magic bar
         STA $0246,Y     ; Set as A's
         RTS

; Restore cursor position in inventory
C30DAC:  LDY $022F       ; Old list pos
         STY $4F         ; Set as current
         TYA             ; List column
         STA $4D         ; Set as onscreen
         LDA $0231       ; Old scroll pos
         BRA C30E1E      ; Restore it, etc.

; Restore cursor position in Skills menu
C30DFF:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $0236,X     ; Former position
         STY $4D         ; Set as current
         RTS

; Restore cursor position in Magic menu
C30E0A:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $023E,X     ; Old list pos
         STY $4F         ; Set as current
         TYA             ; List column
         STA $4D         ; Set as onscreen
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $0246,X     ; Old scroll pos
C30E1E:  STA $4A         ; Set as current
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $4A         ; Sub scroll pos
         STA $4E         ; Set onscreen row
         RTS

; Upload BG1 tilemaps A and B
C30E28:  PEI ($00)       ; VRAM: $0000
         LDY #$3849      ; 7E/3849
         BRA C30E88      ; Move data

; Upload BG1 tilemaps B and C
C30E36:  PEA $0400       ; VRAM: $0400
         LDY #$4049      ; 7E/4049
         BRA C30E88      ; Move data

; Upload BG1 tilemaps C and D
C30E44:  PEA $0800       ; VRAM: $0800
         LDY #$4849      ; 7E/4849
         BRA C30E88      ; Move data

; Upload BG2 tilemaps A and B
C30E52:  PEA $1000       ; VRAM: $1000
         LDY #$5849      ; 7E/5849
         BRA C30E88      ; Move data

; Upload BG2 tilemaps C and D
C30E60:  PEA $1800       ; VRAM: $1800
         LDY #$6849      ; 7E/6849
         BRA C30E88      ; Move data

; Upload BG3 tilemaps A and B
C30E6E:  PEA $4000       ; VRAM: $4000
         LDY #$7849      ; 7E/7849
         BRA C30E88      ; Move data

; Upload BG3 tilemaps C and D
C30E7C:  PEA $4800       ; VRAM: $4800
         LDY #$8849      ; 7E/8849
C30E88:  STY $4302       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4304       ; Set src HB
         PLY             ; VRAM ptr
         STY $2116       ; Set dest
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY #$1000      ; Bytes: 4096
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C30EA2:  RTS

; Play cursor sound
C30EA3:  LDA $AE         ; Started sound
         CMP #$21        ; Cursor's?
         BEQ C30EA2      ; Exit if so
C30EA9:  LDA #$21        ; APU command
         STA $AE         ; Prevent repeat
         BRA C30EC9      ; Set I/O port 0

; Play click sound
C30EB2:  LDA #$20        ; APU command
         BRA C30EC9      ; Set I/O port 0

; Play save sound
C30EB9:  LDA #$23        ; APU command
         BRA C30EC9      ; Set I/O port 0

; Play buzzer sound
C30EC0:  LDA #$22        ; APU command
         BRA C30EC9      ; Set I/O port 0

; Play letter deletion sound
C30EC7:  LDA #$24        ; APU command
C30EC9:  STA $002140     ; Set I/O port 0
         RTS

; Play cash register sound
C30ECE:  LDA #$BF        ; Sound number
C30ED0:  STA $001301     ; Set I/O port 1
         LDA #$18        ; APU command
         STA $001300     ; Set I/O port 0
         LDA #$80        ; Volume specs
         STA $001302     ; Set I/O port 2
         JSL $C50004     ; Update ports
         RTS

; Play recovery sound
C30EE5:  LDA #$C5        ; Sound number
         BRA C30ED0      ; Set vol, etc.

; Set to upload BG1 tilemaps A and B
C30EE9:  JSR C30EFD      ; Set src, dst
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Set to upload BG1 tilemap A
C30EFD:  LDY $00         ; $0000
         STY $14         ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG1 tilemap B
C30F11:  LDY #$0400      ; $0400
         STY $14         ; Set VRAM ptr
         LDY #$4049      ; 7E/4049
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemaps A and B
C30F25:  LDY #$4000      ; $4000
         STY $14         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap A (version 1)
C30F39:  LDY #$4000      ; $4000
         STY $14         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap B (version 1)
C30F4D:  LDY #$4400      ; $4400
         STY $14         ; Set VRAM ptr
         LDY #$8049      ; 7E/8049
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap A (version 2)
C30F61:  LDY #$4000      ; $4000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         RTS

; Set to upload BG3 tilemap B (version 2)
C30F75:  LDY #$4400      ; $4400
         STY $1B         ; Set VRAM ptr
         LDY #$8049      ; 7E/8049
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         RTS

; Disable conditional upload during NMI
C30F89:  STZ $1B         ; Null dst LB
         STZ $1C         ; Null dst HB
         RTS

; Set palette to black
black:   LDA #$C3        ; Source HB
         LDX #C310F4     ; Source LBs
         BRA C30F8_      ; Skip a line

; Load specified palette (for ending)
C30F8E:  LDA #$C2        ; Bank: C2
C30F8_:  STA $ED         ; Set src HB
         STX $EB         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dst HB
         STY $E7         ; Set dst LBs
         LDY #$001F      ; Data index
C30F9C:  LDA [$EB],Y     ; Color data
         STA [$E7],Y     ; Save in RAM
         DEY             ; Index -1
         BPL C30F9C      ; Loop till < 0
         RTS

; Call function below, set slowness to 2
slow2:   LDA #$02        ; Slowness: 2
         BRA C30FAA      ; SKip a line

; Call function below, set slowness to 4
slow4:   LDA #$04        ; Slowness: 4

; Set to gradually convert one palette into another
C30FAA:  PHY             ; Save dst LBs
         PHX             ; Save src LBs
         PHA             ; Save slowness
         LDY #C30FDD     ; C3/0FDD
         JSR qanim0      ; Queue fade fn
         PLA             ; Fade slowness
         STA $7E37CA,X   ; Put in queue
         LDA #$7E        ; Dest HB
         STA $7E36C9,X   ; Put in queue
         LDA $ED         ; Source HB
         STA $7E36CA,X   ; Put in queue
         REP #$20        ; 16-bit A
         PLA             ; Source LBs
         STA $7E3449,X   ; Put in queue
         PLA             ; Dest LBs
         STA $7E33C9,X   ; Put in queue
         SEP #$20        ; 8-bit A
         RTS

; Gradually convert one palette into another
C30FDD:  BNE C30FF6      ; If mode 1

; Mode 0: Initialize timer
C30FE5:  LDA #$1F        ; Frames: 31
         STA $3349,X     ; Set fade timer
         STZ $334A,X     ; Timer HB: 0
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 1: Modify palette
C30FF6:  LDA $35C9,X     ; Delay over?
         BNE C31032      ; Exit if not
         LDA $37CA,X     ; Slowness
         STA $35C9,X     ; Set delay
         LDA $36C9,X     ; Dest HB
         STA $E2         ; Memorize it
         LDA $36CA,X     ; Source HB
         STA $E5         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $33C9,X     ; Dest LBs
         STA $E0         ; Memorize them
         LDA $3449,X     ; Source LBs
         STA $E3         ; Memorize them
         LDA $3349,X     ; Fade timer
         STA $F1         ; Memorize it
         JSR C31037      ; Alter palette
         SEP #$20        ; 8-bit A
         LDX $2D         ; Queue index
         LDA $3349,X     ; Timer expired?
         BEQ C31030      ; Dequeue if so
         DEC $3349,X     ; Fade timer -1
         BNE C31032      ; Branch if > 0
C31030:  CLC             ; Set to dequeue
         RTS             ; Exit
C31032:  DEC $35C9,X     ; Fade delay -1
         SEC             ; Set to requeue
         RTS

; Partially convert one palette into another
C31037:  LDX #$0010      ; Colors: 16
         LDY $00         ; Color index: 0
C3103C:  LDA [$E0],Y     ; Actual color
         STA $E7         ; Memorize it
         LDA [$E3],Y     ; Target color
         STA $E9         ; Memorize it
         JSR C31051      ; Alter color
         STA [$E0],Y     ; Save changes
         INY             ; Color index +1
         INY             ; Color index +1
         DEX             ; One less color
         BNE C3103C      ; Loop till last
         RTS

; Partially convert one color into another
C31051:  LDA $E7         ; Actual color
         AND #$001F      ; Get red
         STA $EB         ; Memorize it
         LDA $E9         ; Target color
         AND #$001F      ; Get red
         SEC             ; Prepare SBC
         SBC $EB         ; Both match?
         BEQ C3106E      ; Skip if so
         BCC C3106C      ; -1 if lesser
         CMP $F1         ; Diff < timer?
         BCC C3106E      ; Skip if so
         INC $EB         ; Red +1
         BRA C3106E      ; Skip a line
C3106C:  DEC $EB         ; Red -1

; Fork: Handle green
C3106E:  LDA $E7         ; Actual color
         AND #$03E0      ; Get green
         STA $ED         ; Memorize it
         LDA $E9         ; Target color
         AND #$03E0      ; Get green
         SEC             ; Prepare SBC
         SBC $ED         ; Both match?
         BEQ C3109B      ; Skip if so
         BCC C31093      ; -1 if lesser
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         XBA             ; Now 0-31
         CMP $F1         ; Diff < timer?
         BCC C3109B      ; Skip if so
         CLC             ; Prepare ADC
         LDA $ED         ; Actual green
         ADC #$0020      ; Green +1
         STA $ED         ; Save changes
         BRA C3109B      ; Do blue
C31093:  LDA $ED         ; Actual green
         SEC             ; Prepare SBC
         SBC #$0020      ; Green -1
         STA $ED         ; Save changes

; Fork: Handle blue
C3109B:  LDA $E7         ; Actual color
         AND #$7C00      ; Get blue
         STA $EF         ; Memorize it
         LDA $E9         ; Target color
         AND #$7C00      ; Get blue
         SEC             ; Prepare SBC
         SBC $EF         ; Both match?
         BEQ C310CB      ; Skip if so
         BCC C310C3      ; -1 if lesser
         SEP #$20        ; 8-bit A
         XBA             ; ÷256
         LSR A           ; ÷512
         LSR A           ; Now 0-31
         REP #$20        ; 16-bit A
         CMP $F1         ; Diff < timer?
         BCC C310CB      ; Skip if so
         CLC             ; Prepare ADC
         LDA $EF         ; Actual blue
         ADC #$0400      ; Blue +1
         STA $EF         ; Save changes
         BRA C310CB      ; Merge RGB
C310C3:  LDA $EF         ; Actual blue
         SEC             ; Prepare SBC
         SBC #$0400      ; Blue -1
         STA $EF         ; Save changes

; Fork: Merge RGB components
C310CB:  LDA $EB         ; Altered red
         ORA $ED         ; Add green
         ORA $EF         ; Add blue
         RTS

; White palette for an ending transition
C310D4:  dw $0000,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF
         dw $7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF

; Black palette for most ending transitions
C310F4:  dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
         dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

; Reset OAM and animation queue
C31114:  JSR db7e        ; Set DB to 7E
;        STX $2F         ; No use...
         JSR C3114E      ; Reset OAM
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         TAX             ; Clear X
         STX $2D         ; Queue index: 0
         LDX #$3249      ; 7E/3249
         LDY #$0580      ; Bytes: 1408
         JMP clr_ram     ; Clear queue

; Reset OAM
C3114E:  LDX $00         ; Index: 0
         REP #$20        ; 16-bit A
C31150:  LDA #$E001      ; X=1, Y=224
         STA $0300,X     ; Put offscreen
         INX             ; Index +1
         INX             ; Index +1
         TDC             ; Clear A
         LDA #$0001      ; Tile num: 1
         STA $0300,X     ; Set attribs
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0200      ; Past Lo-OAM?
         BNE C31150      ; Loop if not
         SEP #$20        ; 8-bit A
         LDX #$001F      ; Hi-OAM index
C31168:  STZ $0500,X     ; Clear Hi-OAM
         DEX             ; Index -1
         BPL C31168      ; Loop till < 0
         RTS

; Queue animation function in slot 0 or further
qanim0:  TDC             ; Min slot: 0
         BRA C31173      ; Queue anim fn

; Queue animation function in slot 8 or further
qanim1:  LDA #$01        ; Min slot: 8
         BRA C31173      ; Queue anim fn

; Queue animation function in slot 16 or further
qanim2:  LDA #$02        ; Min slot: 16
         BRA C31173      ; Queue anim fn

; Queue animation function in slot 24 or further
qanim3:  LDA #$03        ; Min slot: 24

; Queue animation function
C31173:  PHA             ; Save slot
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         PLA             ; Starting slot
         JSR x16         ; x16
         REP #$20        ; 16-bit A
         TAX             ; Index it
C31196:  LDA $3249,X     ; Empty slot?
         BNE C311A0      ; Skip if not
         TYA             ; Animation fn
         STA $3249,X     ; Put in queue
         SEP #$20        ; 8-bit A
         LDA $2D         ; Caller's index
         STA $374A,X     ; Put in queue
;        INC $2F         ; No use...
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Fork: Try next slot
C311A0:  INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Past slot 64?
         BNE C31196      ; Loop if not
         STP             ; Freeze game...

; Process animation queue, hide inactive objects
C311B0:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         LDX #$0300      ; 7E/0300
         STX $0E         ; Set Lo-OAM ptr
         LDX #$0500      ; 7E/0500
         STX $10         ; Set Hi-OAM ptr
         LDA #$03        ; Tile: 1 of 4
         STA $33         ; Set Hi-OAM index
         STZ $34         ; Hi-OAM: 4x 8x8
         LDX #$0080      ; Objects: 128
         STX $31         ; Set space left
         LDX $00         ; Queue index: 0
         REP #$20        ; 16-bit A
C311CE:  LDA $3249,X     ; Animation fn
         BEQ C311F5      ; Skip if blank
         STX $2D         ; Set queue index
         PHX             ; Save index
         STA $2B         ; Set anim fn
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $3649,X     ; Anim mode
         ASL A           ; Double it
         PHB             ; Save DB
         JSR C31203      ; Run anim fn
         PLB             ; Restore DB
         REP #$20        ; 16-bit A
         PLX             ; Queue index
         BCS C311F5      ; Branch if kept
         STZ $3249,X     ; Anim fn: None
         STZ $3649,X     ; Anim mode: 0
         STZ $35C9,X     ; Misc. specs: 0
         STZ $3749,X     ; OAM complements
;        DEC $2F         ; No use...
C311F5:  INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Done 64 slots?
         BNE C311CE      ; Loop if not

; Fork: Hide inactive tiles in OAM
C31338:  LDY $31         ; Unused tiles
         BEQ C3134C      ; Exit if none
         LDX #$01FC      ; Tile: Last
         LDA #$E001      ; X=1, Y=224
C31342:  STA $0300,X     ; Set position
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEY             ; Tiles left -1
         BNE C31342      ; Loop till last
C3134C:  SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Execute queued animation function
C31203:  JMP ($002B)     ; Run anim fn

; Initialize M7 or object's pose number and timer
C3120_:  LDX $2D         ; Queue index
C31206:  REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim ptr LBs
         STA $EB         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $ED         ; Set src HB
         STZ $36C9,X     ; Pose: 1st
         LDY #$0002      ; Skip pose ptr
         LDA [$EB],Y     ; Pose timer
         STA $36CA,X     ; Set sprite's
         RTS

; Handle object's pose timer, then define OAM
C31221:  JSR C31227      ; Pose timer -1
         BRA C31273      ; Define OAM

; Handle pose or Mode 7 timer
C31227:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim ptr LBs
         STA $EB         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $ED         ; Set src HB

; Fork: Handle control codes
C31239:  LDA $36CA,X     ; Pose timer
         CMP #$FE        ; Infinite?
         BEQ C31262      ; Exit if so
;        CMP #$FF        ; Loop point?
         BCC C3124C      ; Branch if not
         STZ $36C9,X     ; Pose: 1st
         JSR C31263      ; Set new timer
         BRA C31239      ; Repeat checks

; Fork: Check if expired
C3124C:  LDA $36CA,X     ; Timer expired?
         BNE C3125F      ; Branch if not
         LDA $36C9,X     ; Pose index
         CLC             ; ...
         ADC #$03        ; Point to next
         STA $36C9,X     ; Save changes
         JSR C31263      ; Set new timer
         BRA C31239      ; Repeat checks

; Fork: Decrease timer
C3125F:  DEC $36CA,X     ; Timer -1
C31262:  RTS

; Initialize pose or Mode 7 timer
C31263:  TDC             ; Clear A
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         INY             ; Skip ptr LB
         INY             ; Skip ptr HB
         LDA [$EB],Y     ; Pose timer
         STA $36CA,X     ; Set object's
         RTS

; Define OAM for object's tiles
C31273:  TDC             ; Clear A
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Pose OAM ptr
         STA $E7         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; OAM ptr HB
         STA $E9         ; Set src HB
         LDY $00         ; Index: 0
         LDA $31         ; OAM's full?
         BEQ C312FB      ; Exit if so
         LDA [$E7],Y     ; Tile count
         STA $E6         ; Memorize it
         BEQ C312FB      ; Exit if none
         INY             ; Index +1

; Fork: Large tile (16x16)
C31297:  LDA [$E7],Y     ; Tile X & flag
         STA $E0         ; Memorize them
         BPL C312B0      ; Branch if 8x8
         TDC             ; Clear A
         LDA $33         ; Hi-OAM index
         TAX             ; Index it
         LDA.L C31334,X  ; Size flag
         CLC             ; Prepare ADC
         ADC $34         ; Add flag pack
         STA $34         ; Set flag pack
         STA ($10)       ; Put in Hi-OAM
         LDX $2D         ; Queue index
         BRA C312B4      ; Skip 2 lines

; Fork: Small tile (8x8)
C312B0:  LDA $34         ; OAM flag pack
         STA ($10)       ; Put in Hi-OAM
C312B4:  LDA $E0         ; Tile's X-Pos
         AND #$7F        ; Clear flag
         STA $E0         ; Save changes

; Fork: Pan with BG1
C312BA:  LDA $364A,X     ; Sprite flags
         LSR A           ; Pan with BG1?
         BCC C312CE      ; Branch if not
         STZ $E1         ; Tile's X HB: 0
         REP #$20        ; 16-bit A
         LDA $E0         ; Tile's rel X
         SEC             ; Prepare SBC
         SBC $35         ; Deduct BG1 X-Pos
         STA $E0         ; Save changes
         SEP #$20        ; 8-bit A

; Fork: Define Lo-OAM, do next tile
C312CE:  JSR C312FC      ; Adjust attribs
         DEC $33         ; Hi-OAM index -1
         BPL C312DF      ; Branch if 0+
         LDA #$03        ; Tile: 1 of 4
         STA $33         ; Reset size index
         STZ $34         ; Hi-OAM: 4x 8x8
         REP #$20        ; 16-bit A
         INC $10         ; Hi-OAM ptr +1
C312DF:  REP #$20        ; 16-bit A
         LDA $E0         ; Tile coords
         STA ($0E)       ; Save in OAM
         INC $0E         ; Lo-OAM ptr +1
         INC $0E         ; Lo-OAM ptr +1
         LDA $E2         ; Tile num/attr
         STA ($0E)       ; Save in OAM
         INC $0E         ; Lo-OAM ptr +1
         INC $0E         ; Lo-OAM ptr +1
         SEP #$20        ; 8-bit A
         DEC $31         ; Space left -1
         BEQ C312FB      ; Exit if full
         DEC $E6         ; Tiles left -1
         BNE C31297      ; Loop till last
C312FB:  RTS

; Determine object tile's coordinates, load attributes
C312FC:  LDA $E0         ; Tile's rel X
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add object's X
         STA $E0         ; Save changes
         INY             ; Index +1
         LDA [$E7],Y     ; Tile's rel Y
         CLC             ; Prepare ADC
         ADC $344A,X     ; Add object's Y
         STA $E1         ; Memorize sum
         INY             ; Index +1
         LDA [$E7],Y     ; Tile num LSBs
         STA $E2         ; Memorize them
         INY             ; Index +1
         LDA $364A,X     ; Sprite flags
         BIT #$02        ; Mirror H-wise?
         BEQ C31320      ; Branch if not
         LDA [$E7],Y     ; Tile attributes
         ORA #$40        ; Add H-Flip
         BRA C31322      ; Skip a line
C31320:  LDA [$E7],Y     ; Tile attributes
C31322:  STA $E3         ; Memorize them
         LDA $3749,X     ; OAM complements
         BEQ C31332      ; Exit if none
         LDA $E3         ; Tile attributes
         AND #$F1        ; Clear palette
         ORA $3749,X     ; Add complements
         STA $E3         ; Save changes
C31332:  INY             ; Index +1
         RTS

; Hi-OAM complements
C31334:  db $80          ; Tile 4: Large
         db $20          ; Tile 3: Large
         db $08          ; Tile 2: Large
         db $02          ; Tile 1: Large

; Trigger NMI, decode joypads, etc.
C3134D:  JSR C31368      ; Trigger NMI
         LDA $46         ; Menu flags
         BIT #$20        ; Scroll list?
         BEQ C31359      ; Branch if not
         JSR C38105      ; Scroll BG1
C31359:  JSL C3A46E      ; Decode joypads
         LDA $20         ; Transition timer
         BEQ C31367      ; Exit if off
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $08         ; No-autofire keys
         STY $0A         ; Semi-auto keys
C31367:  RTS

; Trigger NMI, allow cursor sound to repeat
C31368:  LDA #$81        ; Stop IRQ timers
         STA $4200       ; On: NMI, joypads
         STA $24         ; Mark NMI request
         CLI             ; Unmask IRQs
C31370:  LDA $24         ; Back from NMI?
         BNE C31370      ; Loop if not
         SEI             ; Mask IRQs
         LDA $44         ; Brightness
         STA $2100       ; Apply it now
         LDA $43         ; Queued HDMA
         STA $420C       ; Update channels
         LDA $B5         ; Mosaic settings
         STA $2106       ; Apply to screen
         STZ $AE         ; Allow SFX repeat
         RTS

; Handle NMI (menu, ending)
C31387:  REP #$30        ; 16-bit A, X, Y
         PHA             ; Save A
         PHX             ; Save X
         PHY             ; Save Y
         PHB             ; Save DB
         PHD             ; Save DP
         SEP #$20        ; 8-bit A
         LDA $4210       ; Clear NMI flag
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         PEI ($00)       ; Push #$0000
         PLD             ; Set DP to 0
         LDA $24         ; Manual NMI?
         BEQ C313B1      ; Branch if not
         JSR C31412      ; Refresh screen
         LDY $CF         ; Ending timer
         INY             ; Ending timer +1
         STY $CF         ; Save changes
         LDY $20         ; Transition timer
         BEQ C313B1      ; Ignore if off
         DEY             ; Timer -1
         STY $20         ; Save changes
C313B1:  JSL $C00015     ; Event timers -1
         JSL C313C8      ; Play time +1
         INC $23         ; NMI count +1
         TDC             ; Clear A
         STA $24         ; Unmark manual NMI
         REP #$30        ; 16-bit A, X, Y
         PLD             ; Restore DP
         PLB             ; Restore DB
         PLY             ; Restore Y
         PLX             ; Restore X
         PLA             ; Restore A
         RTI

; Handle IRQ...
C313C7:  RTI

; Advance play time (NMI)
C313C8:  LDA $021E       ; Frames
         CMP #$3C        ; 60?
         BNE C313FC      ; Branch if not

; Fork: Seconds +1
C313D1:  STZ $021E       ; Frames = 0
         LDA $021D       ; Seconds
         CMP #$3B        ; 59?
         BEQ C313E0      ; +1 min if so
         INC $021D       ; +1 second
         BRA C313FC      ; +1 frame

; Fork: Minutes +1
C313E0:  STZ $021D       ; Seconds = 0
         LDA $021C       ; Minutes
         CMP #$3B        ; 59?
         BEQ C313EF      ; +1 hour if so
         INC $021C       ; +1 minute
         BRA C313FC      ; +1 frame

; Fork: Hours +1
C313EF:  STZ $021C       ; Minutes = 0
         LDA $021B       ; Hours
         CMP #$63        ; 99?
         BEQ C313FC      ; Branch if so
         INC $021B       ; +1 hour

; Fork: Frames +1
C313FC:  LDX $021B       ; Hours and mins
         CPX #$3B63      ; 99:59?
         BNE C3140D      ; Branch if not
         STZ $021D       ; Seconds = 0
C3140D:  INC $021E       ; +1 frame
         TDC             ; Clear A
         RTL

; Refresh screen (NMI)
C31412:  STZ $420C       ; Disable HDMA
         LDA $35         ; BG1 X-Pos LB
         STA $210D       ; Apply it now
         LDA $36         ; BG1 X-Pos HB
         STA $210D       ; Apply it now
         LDA $37         ; BG1 Y-Pos LB
         STA $210E       ; Apply it now
         LDA $38         ; BG1 Y-Pos HB
         STA $210E       ; Apply it now
         LDA $39         ; BG2 X-Pos LB
         STA $210F       ; Apply it now
         LDA $3A         ; BG2 X-Pos HB
         STA $210F       ; Apply it now
         LDA $3B         ; BG2 Y-Pos LB
         STA $2110       ; Apply it now
         LDA $3C         ; BG2 Y-Pos HB
         STA $2110       ; Apply it now
         LDA $3D         ; BG3 X-Pos LB
         STA $2111       ; Apply it now
         LDA $3E         ; BG3 X-Pos HB
         STA $2111       ; Apply it now
         LDA $3F         ; BG3 Y-Pos LB
         STA $2112       ; Apply it now
         LDA $40         ; BG3 Y-Pos HB
         STA $2112       ; Apply it now
         JSR C3D263      ; Refresh Mode 7
         JSR C31463      ; Refresh OAM
         JSR C314D2      ; Refresh CGRAM
         JSR C31488      ; Do VRAM DMA A
         BRA C314AC      ; Do VRAM DMA B

; Refresh OAM (NMI)
C31463:  LDX $00         ; $0000
         STX $2102       ; Set OAM address
         LDA #$02        ; 1Rx2B to PPU
         STA $4300       ; Set DMA mode
         LDA #$04        ; $2104
         STA $4301       ; To OAM
         LDY #$0300      ; 00/0300
         STY $4302       ; Set src LBs
         STZ $4304       ; Src HB: 00
         LDY #$0220      ; Bytes: 544
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Handle absolute VRAM transfer (NMI)
C31488:  LDY $14         ; Destination
         STY $2116       ; Set VRAM ptr
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY $16         ; Source LBs
         STY $4302       ; Set CH0's
         LDA $18         ; Source HB
         STA $4304       ; Set CH0's
         LDY $12         ; Number of bytes
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Handle conditional VRAM transfer (NMI)
C314AC:  LDY $1B         ; Destination
         BEQ C314D1      ; Exit if none
         STY $2116       ; Set VRAM ptr
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY $1D         ; Source LBs
         STY $4302       ; Set CH0's
         LDA $1F         ; Source HB
         STA $4304       ; Set CH0's
         LDY $19         ; Number of bytes
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C314D1:  RTS

; Refresh CGRAM (NMI)
C314D2:  LDA $45         ; Menu flags
         LSR A           ; Freeze CGRAM?
         BCC C314FD      ; Exit if so
         STZ $2121       ; To BG color 0
         LDA #$02        ; 1Rx2B to PPU
         STA $4300       ; Set DMA mode
         LDA #$22        ; $2122
         STA $4301       ; To CGRAM
         LDY #$3049      ; 7E/3049
         STY $4302       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4304       ; Set src HB
         LDY #$0200      ; Bytes: 512
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C314FD:  RTS

; Load save data on defeat
C314FE:  LDA $021F       ; File number
         BEQ C31514      ; Reset if none
         JSR C31566      ; Load save file
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Bad checksum?
         BEQ C31514      ; Reset game if so
         JSR C31595      ; Move timer data
         TDC             ; Reset game: No
         BRA C31518      ; Set aftereffect

; Fork: Reset game
C31514:  LDA #$FF        ; Reset game: Yes
C31518:  STA $0205       ; Set aftereffect
         TDC             ; ...
         RTL

; Record game data
C3151D:  AND #$03        ; File number
         STA $307FF0     ; Set last altered
         STA $0224       ; Set last viewed
         PHA             ; Memorize slot
         LDY $021B       ; Hrs, mins played
         STY $1863       ; To SRAM block
         LDA $021D       ; Seconds played
         STA $1865       ; To SRAM block
         JSR C31586      ; Move timer data
         JSR C319D1      ; Compute checksum
         STY $1FFE       ; Put in SRAM block
         TDC             ; Clear A
         PLA             ; File number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3155E-2,X; SRAM pointer
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY $00         ; RAM index: 0
C3154D:  LDA $1600,Y     ; Game data
         STA $306000,X   ; Save in SRAM
         INX             ; SRAM index +1
         INY             ; RAM index +1
         CPY #$0A00      ; At $2000?
         BNE C3154D      ; Loop if not
         JMP C37083      ; Mark all files

; SRAM pointers
C3155E:  dw $0000        ; Save slot 1
         dw $0A00        ; Save slot 2
         dw $1400        ; Save slot 3

; Load save file
C31566:  PHA             ; Push file
         TDC             ; Clear A
         PLA             ; Pull file
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3155E-2,X; SRAM pointer
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY $00         ; RAM index: 0
C31577:  LDA $306000,X   ; Saved data
         STA $1600,Y     ; Copy to RAM
         INX             ; SRAM index +1
         INY             ; RAM index +1
         CPY #$0A00      ; At $2000?
         BNE C31577      ; Loop if not
         RTS

; Copy event timer data to save area
C31586:  LDX #$0017      ; Base index
C31588:  LDA $1188,X     ; Timer data
         STA $1FA8,X     ; Put in SRAM
         DEX             ; Index -1
         BPL C31588      ; Loop till < 0
         RTS

; Restore saved event timer data
C31595:  LDX #$0017      ; Base index
C31597:  LDA $1FA8,X     ; Timer data
         STA $1188,X     ; Make active
         DEX             ; Index -1
         BPL C31597      ; Loop till < 0
         RTS

; Handle D-Pad for Save menu
C315AA:  JSR C3072D      ; Handle D-Pad
C315AD:  LDY #C315CE     ; C3/15CE
         JMP C30640      ; Relocate cursor

; Handle D-Pad for Load menu
C315BE:  JSR C3072D      ; Handle D-Pad
C315C1:  LDY #C315CC     ; C3/15CC
         JMP C30640      ; Relocate cursor

; Load navigation data for save file confirmation
C315D4:  LDY #C315E3     ; C3/15E3
         JMP C305FE      ; Load navig data

; Handle D-Pad for save file confirmation
C315DA:  JSR C3072D      ; Handle D-Pad
C315DD:  LDY #C315E8     ; C3/15E8
         JMP C30640      ; Relocate cursor

; Draw Save menu, load skins, list actor sprites
C315EC:  JSR C36A28      ; Clear BG2 map A
         JSR C31632      ; Handle files
         JSR C33A87      ; Load skin visuals
         LDX #C3189C     ; C3/189C
         JSR C30341      ; Draw top window
         JSR C3C2F2      ; Color: User's
         LDY #C31A78     ; Text pointer
         JSR C302F9      ; Draw "Save"
         BRA C31890      ; Upload tilemaps

; Draw Load menu, load skins, list actor sprites
C31608:  JSR C36A28      ; Clear BG2 map A
         STZ $1D4E       ; Skin: 1st; etc.
         JSR C36BBC      ; Reset skin colors
         JSR C33A87      ; Load skin visuals
         LDX #C3189C     ; C3/189C
         JSR C30341      ; Draw top window
         LDA $1D4E       ; Game options
         AND #$70        ; Reset skin, gauge
         STA $1D4E       ; Save changes
         JSR C31632      ; Handle files
         JSR C3C2F2      ; Color: User's
         LDY #C31A7F     ; Text pointer
         JSR C302F9      ; Draw "New Game"
C31890:  JMP C35D77      ; Upload tilemaps

; Output all save files
C31632:  JSR C36C60      ; Load grayscale
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         LDY #$7FFF      ; Color: White
         JSR C33F9_      ; Put in palettes
         LDA #$01        ; Gradient set: 1
         JSL $D4CA1D     ; Create gradient
         JSR C36A15      ; Clear BG1 map A
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A46      ; Clear BG3 map C
         JSR C318AC      ; Move game's SRAM

; Fork: Load save file 1
C31663:  LDA #$01        ; File: 1
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Test validity
         STY $91         ; Save checksum
         BEQ C31682      ; Branch if invalid
         JSR C36F61      ; List char sprites
         JSR C3171D      ; Draw file 1 text
         JSR C33AF5      ; Load skin colors
         BRA C31695      ; Handle file 2

; Fork: Blank file 1
C31682:  JSR C318C1      ; Restore skin 1
         JSR C36F61      ; Use blank party
         JSR C3C2F2      ; Color: White
         LDY #C31A24     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         JSR C33AF5      ; Load skin 1 pal

; Fork: Load save file 2
C31695:  LDA #$02        ; File: 2
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Test validity
         STY $93         ; Save checksum
         BEQ C316B4      ; Branch if invalid
         JSR C36FB8      ; List char sprites
         JSR C317CA      ; Draw file 2 text
         JSR C33B09      ; Load skin colors
         BRA C316C7      ; Handle file 3

; Fork: Blank file 2
C316B4:  JSR C318C1      ; Restore skin 1
         JSR C36FB8      ; Use blank party
         JSR C3C2F2      ; Color: White
         LDY #C31A2C     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         JSR C33B09      ; Load skin 1 pal

; Fork: Load save file 3
C316C7:  LDA #$03        ; File: 3
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Test validity
         STY $95         ; Save checksum
         BEQ C316E6      ; Branch if invalid
         JSR C36FDC      ; List char sprites
         JSR C3182D      ; Draw file 3 text
         JSR C33B1D      ; Load skin colors
         BRA C316F9      ; Draw all windows

; Fork: Blank file 3
C316E6:  JSR C318C1      ; Restore skin 1
         JSR C36FDC      ; Use blank party
         JSR C3C2F2      ; Color: White
         LDY #C31A34     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         JSR C33B1D      ; Load skin 1 pal

; Fork: Draw windows and upload skins
C316F9:  JSR C318C1      ; Restore SRAM
         JSR C33AA1      ; Upload skin A
         LDX #C318A0     ; C3/18A0
         JSR C30341      ; Draw window A
         JSR C33ABD      ; Upload skin B
         LDX #C318A4     ; C3/18A4
         JSR C30341      ; Draw window B
         JSR C33AD9      ; Upload skin C
         LDX #C318A8     ; C3/18A8
         JSR C30341      ; Draw window C
         LDY #$1C00      ; Palette: 7
         JMP C30326      ; Build skin map

; Draw all text for save file 1
C3171D:  JSR C3C2F2      ; Color: White
         LDY #C31A51     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C304E0      ; Turn into text
         LDX #$7B0D      ; Text position
         JSR C304B6      ; Draw hours
         LDA $1864       ; Minutes played
         JSR C304F9      ; Turn into text
         LDX #$7B13      ; Text position
         JSR C304B6      ; Draw minutes
         JSR C3174D      ; Draw leader info
         JSR C3C2F7      ; Color: Blue
         LDY #C31A3C     ; Text pointer
         JMP C302F9      ; Draw "Time"

; Draw leader info for save file 1
C3174D:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C3174F:  LDA $69,X       ; Actor in slot
         BPL .okay       ; Branch if any
         INX             ; Member slot +1
         BRA C3174F      ; Try next member
.okay    JSR C317BE      ; Actor address
         JSR C3C2F7      ; Color: Blue
         LDY #C31A5D     ; Text pointer
         JSR C302F9      ; Draw "LV"
         JSR C3C2F2      ; Color: White
         LDY #C31A6C     ; Text pointer
         JSR C302F9      ; Draw "/"
         PEA $3A4F       ; Name position
         PEA $7AFD       ; Max HP position
         PEA $7AF3       ; HP position
         PEA $7A81       ; Level position
;        BRA C3177F      ; Draw stats

; Draw leader's stats over save file
C3177F:  LDX $67         ; Actor's address
         LDA $08,X       ; Level
         JSR C304E0      ; Turn into text
         PLX             ; Text position
         JSR C304B6      ; Draw 2 digits
         LDY $67         ; Actor's address
         JSR C32B9A      ; Truncate HP
         LDX $09,Y       ; Current HP
         STX $F3         ; Memorize it
         JSR C3052E      ; Turn into text
         PLX             ; Text position
         JSR C30490      ; Draw 4 digits
         LDY $67         ; Actor address
         LDX $0B,Y       ; Max HP
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         JSR C3052E      ; Turn into text
         PLX             ; Text position
         JSR C30490      ; Draw 4 digits
         PLY             ; Text position
         JMP C334CF      ; Draw actor name

; Get member's SRAM block address
C317BE:  TDC             ; Clear A
         TXA             ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; SRAM address
         STX $67         ; Save for later
         RTS

; Draw all text for save file 2
C317CA:  JSR C3C2F2      ; Color: White
         LDY #C31A55     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C304E0      ; Turn into text
         LDX #$7CCD      ; Text position
         JSR C304B6      ; Draw 2 digits
         LDA $1864       ; Minutes played
         JSR C304F9      ; Turn into text
         LDX #$7CD3      ; Text position
         JSR C304B6      ; Draw 2 digits
         JSR C317FA      ; Draw leader info
         JSR C3C2F7      ; Color: Blue
         LDY #C31A43     ; Text pointer
         JMP C302F9      ; Draw "Time"

; Draw leader info for save file 2
C317FA:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C317FC:  LDA $69,X       ; Actor in slot
         BMI C3182A      ; Skip if empty
         JSR C317BE      ; Get its address
         JSR C3C2F7      ; Color: Blue
         LDY #C31A62     ; Text pointer
         JSR C302F9      ; Draw "LV"
         JSR C3C2F2      ; Color: White
         LDY #C31A70     ; Text pointer
         JSR C302F9      ; Draw "/"
         PEA $3C0F       ; Name position
         PEA $7CBD       ; Max HP position
         PEA $7CB3       ; HP position
         PEA $7C41       ; Level position
         JMP C3177F      ; Draw stats
C3182A:  INX             ; Member slot +1
         BRA C317FC      ; Try next member

; Draw all text for save file 3
C3182D:  JSR C3C2F2      ; Color: White
         LDY #C31A59     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C304E0      ; Turn into text
         LDX #$7E8D      ; Text position
         JSR C304B6      ; Draw 2 digits
         LDA $1864       ; Minutes played
         JSR C304F9      ; Turn into text
         LDX #$7E93      ; Text position
         JSR C304B6      ; Draw 2 digits
         JSR C3185D      ; Draw leader info
         JSR C3C2F7      ; Color: Blue
         LDY #C31A4A     ; Text pointer
         JMP C302F9      ; Draw "Time"

; Draw leader info for save file 3
C3185D:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C3185F:  LDA $69,X       ; Actor in slot
         BMI C3188D      ; Skip if empty
         JSR C317BE      ; Get its address
         JSR C3C2F7      ; Color: Blue
         LDY #C31A67     ; Text pointer
         JSR C302F9      ; Draw "LV"
         JSR C3C2F2      ; Color: White
         LDY #C31A74     ; Text pointer
         JSR C302F9      ; Draw "/"
         PEA $3DCF       ; Name position
         PEA $7E7D       ; Max HP position
         PEA $7E73       ; HP position
         PEA $7E01       ; Level position
         JMP C3177F      ; Draw stats
C3188D:  INX             ; Member slot +1
         BRA C3185F      ; Try next member

; Back up SRAM block
C318AC:  LDX #$09FF      ; Init index
C318B4:  LDA $1600,X     ; SRAM data
         STA $7EAC8D,X   ; Make backup
         DEX             ; Index -1
         BPL C318B4      ; Loop till < 0
         RTS

; Restore SRAM block
C318C1:  LDX #$09FF      ; Init index
C318C3:  LDA $7EAC8D,X   ; Data backup
         STA $1600,X     ; Restore it
         DEX             ; Index -1
         BPL C318C3      ; Loop till < 0
         RTS

; Set to condense BG3 text (save file confirmation, Colosseum matchup)
C318D1:  LDY #C318F0     ; Source LBs
         JMP bg3v        ; Queue BG3 V-Pan

; Create actor sprites for Save or Load menu
C31903:  LDX $00         ; Actor slot: 1
C31905:  LDA $7EAA71,X   ; Empty slot?
         BMI C31977      ; Skip if so
         PHX             ; Save slot
         PHX             ; Save slot
         LDY #C319C7     ; C3/19C7
         JSR qanim3      ; Queue OAM fn
         TXY             ; Queue index
         PLX             ; Actor slot
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         LDA $66         ; On "New Game"?
         BEQ C31931      ; Branch if so
         DEC A           ; On file 1?
         BEQ C31943      ; Branch if so
         DEC A           ; On file 2?
         BEQ C3193A      ; Branch if so
         LDA.L C319BB,X  ; OAM complements
         BRA C31947      ; Set coords/ptr

; Fork: New Game
C31931:  LDA.L C31997,X  ; OAM complements
         BRA C31947      ; Set coords/ptr

; Fork: Save file 2
C3193A:  LDA.L C319AF,X  ; OAM complements
         BRA C31947      ; Set coords/ptr

; Fork: Save file 1
C31943:  LDA.L C319A3,X  ; OAM complements
C31947:  STA $3749,Y     ; Set sprite's
         LDA.L C3197F,X  ; X position
         STA $33CA,Y     ; Set sprite's
         LDA.L C3198B,X  ; Y position
         STA $344A,Y     ; Set sprite's
         TDC             ; Clear A
         LDA $AA71,X     ; Graphics set
         JSR C378FA      ; Set anim ptr
         PLB             ; Restore DB
         PLX             ; Actor slot
C31977:  INX             ; Point to next
         CPX #$000C      ; Done all 12?
         BNE C31905      ; Loop if not
;        SEC             ; Set to requeue
         RTS

; Display actor's sprite on save file
C319C7:  JSR C3120_      ; Set pose timer
         JSR C31221      ; Define OAM
         CLC             ; Set to dequeue
         RTS

; Compute SRAM checksum
C319D1:  LDX #$09FD      ; SRAM index
         TDC             ; Checksum: 0
.loop    CLC             ; Prepare ADC
         ADC $1600,X     ; Add SRAM byte
         BCC .next       ; If no overflow
         XBA             ; Checksum HB
         INC A           ; Add one
         XBA             ; Checksum LB
.next    DEX             ; SRAM index -1
         BPL .loop       ; Loop till < 0
         TAY             ; Put sum in Y
         RTS

; Validate computed SRAM checksum (buggy if zero)
C319EB:  CPY $1FFE       ; Sum in save file
         BEQ C319F7      ; Exit if identical
         LDY $00         ; Clear checksum
C319F7:  TYX             ; Z-Flag = Validity
         RTS

; 53: Queue fade-out for save menu
C319FB:  JSR C3304F      ; Queue fade-out
         BRA C31A0D      ; Skip a line

; 52: Queue fade-in for save menu
C31A0A:  JSR C33056      ; Queue fade-in
C31A0D:  LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$54        ; C3/1A19
         STA $26         ; Next: Wait
         BRA C31A21      ; Create actors

; 54: Wait while save menu fades in or out
C31A19:  LDY $20         ; Timer expired?
         BNE C31A21      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C31A21:  JMP C31903      ; Refresh actors

; 04: Initialize main menu
C31A8A:  JSR C3352F      ; Reset/Stop stuff
         JSR C31BA8      ; Load portraits
         JSR C30F89      ; Stop VRAM DMA B
         JSR C33A6B      ; Set Win2 bounds
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue Win1 HDMA
         JSR C36904      ; Reset BGs' X/Y
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$43        ; 64x64 at $4000
         STA $2109       ; Set BG3 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C330F5      ; Draw menu
         LDY #C32F42     ; C3/2F42
         JSR qanim0      ; Queue D-Pad fn
         JSR C307B0      ; Queue cursor OAM
         JSR C3354E      ; HDMA: MS desig.
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C336A3      ; Set to shift BG3
         LDA #$05        ; C3/1DA4
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 07: Initialize Item menu
C31AD6:  JSR C31AE2      ; Init list vars
         JSR C31AFE      ; Draw menu; cursor
         JSR C31B0E      ; Shift & OBJ & Fade
         BRA C31B2E      ; Queue: Choice 1

; Initialize item list variables (Item, Colosseum)
C31AE2:  JSR C3352F      ; Reset/Stop stuff
         JSR C31B99      ; Queue desc anim
         JSR C36904      ; Reset BGs' X/Y
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         LDA #$F5        ; Top row: Slot 246
         STA $5C         ; Set scroll limit
         LDX #$010A      ; Onscreen rows: 10
         STX $5A         ; Onscreen cols: 1
         JMP C37D1C      ; Load navig data

; Draw Item menu, position cursor in inventory
C31AFE:  LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C31B08      ; Branch if not
         JSR C30DAC      ; Restore cursor
C31B08:  JSR C37D25      ; Relocate cursor
         JMP C37DA3      ; Draw menu; elems

; Initiate text shifting, sprites, fade-in (Item, Colosseum)
C31B0E:  JSR C37E2B      ; Set to shift text
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C3BC0_      ; Create scrollbar

; Queue Item menu choice 1, prepare fade-in
C31B2E:  LDA #$08        ; C3/1EF7
         STA $27         ; Queue: Choice 1
         JMP C33541      ; BRT:1 + NMI

; 77: Return from item usage menu
C31B35:  JSR C31AE2      ; Init list vars
         LDA $8E         ; Old cursor column
         STA $4D         ; Set onscreen col
         JSR oldcur      ; Restore cursor pos
         JSR C37D25      ; Relocate cursor
         JSR C37DA3      ; Draw menu; elems
         JSR C31B0E      ; Shift & OBJ & Fade
         BRA C31B2E      ; Queue: Choice 1

; 09: Initialize Skills menu
C31B5B:  JSR C3352F      ; Reset/Stop stuff
         TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor in slot
         JSL $C20006     ; Get actor stats
         JSR C31BA8      ; Load portraits
         JSR C36A08      ; Set Win1 bounds
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C34DBC      ; Set to shift text
         JSR C34C80      ; Draw menu, etc.
         JSR C34B50      ; Load navig data
         LDA $1D4E       ; Game options
         ASL             ; Cursor memory?
         BPL C31B85      ; Branch if not
         JSR C30DFF      ; Restore cursor
C31B85:  JSR C34B59      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C31B99      ; Queue desc anim
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$0A        ; C3/1FF4
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; Set to update and upload description
C31B99:  JSR C3A796      ; Clear desc GFX
         JSR C3A991      ; Queue desc upload
         LDY #C3A80E     ; C3/A80E
         JMP qanim0      ; Queue desc update

; Load portrait graphics and colors for party
C31BA8:  JSR C36915      ; Get party info
         JSR C36E82      ; Load graphics
         JSR C36C09      ; Load colors
         LDA #$05        ; Show cursor: Y
         TSB $45         ; Unfreeze CGRAM
         JMP C314D2      ; Refresh CGRAM

; 35: Initialize Equip menu
C31BB8:  JSR C31BBD      ; Init variables
C31BD7:  JSR C39032      ; Draw menu; status
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$36        ; C3/9621
         STA $27         ; Queue: Option list
         JMP C33541      ; BRT:1 + NMI

; Initialize variables for Equip menu
C31BBD:  JSR C3352F      ; Reset/Stop stuff
         JSR C36A08      ; Set Win1 bounds
         LDA #$06        ; Main cursor: On
         TSB $46         ; Set menu flag
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C394B6      ; Set to shift text
         JSR C38E50      ; Load navig data
         JSR C38E59      ; Relocate cursor
         JMP C307B0      ; Queue cursor OAM

; 7E: Swap actor in Equip menu, retain Equip mode
C31BE5:  JSR C31C01      ; Draw menu, etc.
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C31C0A      ; Cursor & Fade-in
         LDA #$55        ; C3/9884
         BRA C31C15      ; Queue slot choice

; 7F: Swap actor in Equip menu, retain Remove mode
C31BF3:  JSR C31C01      ; Draw menu, etc.
         JSR C39656      ; Draw blue "REMOVE"
         JSR C31C0A      ; Cursor & Fade-in
         LDA #$56        ; C3/98CF
;        BRA C31C15      ; Queue slot choice

; Set queued menu command, prepare fade-in
C31C15:  STA $27         ; Set queued cmd
         JMP C33541      ; BRT:1 + NMI

; Redraw Equip menu after actor swap
C31C01:  JSR C31BBD      ; Reset variables
         JSR C39032      ; Draw menu; status
         JMP C39614      ; Switch windows

; Put cursor on first gear slot, trigger fade-in
C31C0A:  LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JSR C38E6C      ; Load navig data
         JMP C38E75      ; Relocate cursor

; 6D: Open Equip menu after optimizing gear
C31C1A:  JSR C31BBD      ; Init variables
         JSR C396F0      ; Optimize gear
         LDA #$02        ; Menu: Equip
         STA $25         ; Set submenu
         BRA C31BD7      ; Draw menu, etc.

; 6E: Open Equip menu after removing all gear
C31C26:  JSR C31BBD      ; Init variables
         JSR C396A8      ; Remove gear
         LDA #$02        ; Menu: Equip
         STA $25         ; Set submenu
         BRA C31BD7      ; Draw menu, etc.

; 38: Initialize party gear overview
C31C32:  JSR C3352F      ; Reset/Stop stuff
         JSR C39497      ; Set to shift text
         JSR C38EED      ; Draw menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$39        ; C3/2966
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 0B: Initialize Status menu
C31C46:  JSR C3352F      ; Reset/Stop stuff
         JSR C3620B      ; Set to shift text
         JSR C35D05      ; Draw menu; portrait
         JSR C31C5D      ; Init cursor data
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$0C        ; C3/21F5
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; Initialize cursor data for Status menu
C31C5D:  JSR gogo1       ; Actor = Gogo?
         BNE C31C78      ; Abort if not
         JSR C336FF      ; Load navig data
         JSR C33708      ; Relocate cursor
         LDA #$06        ; Main cursor: On
         TSB $46         ; Set menu flag
         JMP C307B0      ; Queue cursor OAM
C31C78:  LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         RTS

; 0D: Initialize Config menu
C31C7D:  JSR C3352F      ; Reset/Stop stuff
         STZ $4A         ; Screen: 1st
         JSR C33A4C      ; Set Win2 bounds
         JSR C3389E      ; Draw menu, etc.
         JSR C33858      ; Load navig data
         LDA $5F         ; Return position
         STA $4E         ; Set cursor row
         JSR C33861      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$0E        ; C3/22C5
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 13: Initialize Save menu
C31CA0:  JSR C3352F      ; Reset/Stop stuff
;        LDY #$0002      ; Y: 2
;        STY $37         ; Set BG1 Y-Pos
;        JSR C336A3      ; Set to shift BG3...
         LDA #$E3        ; CH: 0-1, 5-7
         TRB $43         ; Halt HDMA channels
         JSR C315EC      ; Draw menu, get chars
         JSR C36CC7      ; Load actor colors
         JSR C36C84      ; Load cursor colors
         LDY #C315B3     ; C3/15B3
         JSR C305FE      ; Load navig data
         LDY $91         ; File 1 checksum
         BNE C31CC7      ; Branch if not 0
         LDY $93         ; File 2 checksum
         BNE C31CC7      ; Branch if not 0
         LDY $95         ; File 3 checksum
         BEQ C31CCD      ; Branch if 0
C31CC7:  LDA $0224       ; Last viewed file
         DEC A           ; Now 0-2
         STA $4E         ; Set cursor row
C31CCD:  JSR C315AD      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set active file
         LDA #$52        ; C3/1A0A
         STA $26         ; Next: Fade-in
         LDA #$14        ; C3/2540
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 15: Initialize save confirmation
C31CE3:  JSR C3352F      ; Reset/Stop stuff
         JSR C36915      ; Get party info
         JSR C33128      ; Draw menu
         JSR C315D4      ; Load navig data
         JSR C315DD      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C318D1      ; Set to shift text
         LDA #$16        ; C3/259D
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 20: Initialize Load menu
C31D03:  JSR C3352F      ; Reset/Stop stuff
;        JSR C336A3      ; Set to shift BG3...
         LDA #$E3        ; CH: 0-1, 5-7
         TRB $43         ; Halt HDMA channels
;        LDY $00         ; X: 0
;        STY $35         ; Set BG1 X-Pos
;        STY $39         ; Set BG2 X-Pos
;        STY $3D         ; Set BG3 X-Pos
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C31608      ; Draw menu, get chars
         JSR C36CC7      ; Load actor colors
         JSR C36C84      ; Load cursor colors
         LDY #C315C7     ; C3/15C7
         JSR C305FE      ; Load navig data
         LDY $91         ; File 1 checksum
         BNE C31D36      ; Branch if not 0
         LDY $93         ; File 2 checksum
         BNE C31D36      ; Branch if not 0
         LDY $95         ; File 3 checksum
         BEQ C31D3C      ; Branch if 0
C31D36:  LDA $307FF0     ; Last altered file
         STA $4E         ; Set cursor row
C31D3C:  JSR C315C1      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA $4B         ; Cursor slot
         STA $66         ; Set active file
         LDA #$21        ; C3/29C2
         STA $27         ; Queue: Sustain menu
         LDA #$52        ; C3/1A0A
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 22: Initialize load confirmation
C31D51:  JSR C3352F      ; Reset/Stop stuff
         JSR C36915      ; Get party info
         JSR C3314C      ; Draw menu
         JSR C315D4      ; Load navig data
         JSR C315DD      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C318D1      ; Set to shift text
         LDA #$23        ; C3/B466
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 00: Queue fade-out, prepare transition
C31D71:  JSR C3304F      ; Queue fade-out
         BRA C31D81      ; Skip a line

; 01: Queue fade-in, prepare transition
C31D7E:  JSR C33056      ; Queue fade-in
C31D81:  LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$02        ; C3/1D8B
         STA $26         ; Next: Wait
         RTS

; 02: Wait while menu fades in or out
C31D8B:  LDY $20         ; Timer expired?
         BNE C31D93      ; Exit if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C31D93:  RTS

; 03: Exit main menu's portrait area
C31D94:  LDA #$05        ; C3/1DA4
         STA $26         ; Next: Main menu
         LDY #C32F42     ; C3/2F42
         JSR qanim0      ; Queue D-Pad fn
         JMP C307B0      ; Queue cursor OAM

; 05: Sustain main menu
C31DA4:  JSR C33548      ; Redraw time
         LDA $08         ; Pushing A?
         BPL C31DB0      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Chosen menu
         STA $25         ; Set submenu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32E6C,X)  ; Handle choice

; Fork: Handle left
C31DB0:  LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C31DBC      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         JMP C32EC6      ; Init Order menu

; Fork: Handle B
C31DBC:  LDA $09         ; Pushing B?
         BPL C31DD1      ; Exit if not
         STZ $0205       ; Clear field event
         JSR C30EA9      ; Sound: Cursor
         JSR C31DD2      ; Update field FX
fdexit:  LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
C31DD1:  RTS

; Update field effects from gear (Charms, Sprint Shoes)
C31DD2:  STZ $11DF       ; Clear effects
         LDX $00         ; Member slot: 1
C31DD7:  LDA $69,X       ; Actor in slot
         BMI C31DE1      ; Skip if none
         PHX             ; Save slot
         JSL $C20006     ; Load gear FX
         PLX             ; Member slot
C31DE1:  INX             ; Slot +1
         CPX #$0004      ; Done all 4?
         BNE C31DD7      ; Loop if not
C31DE7:  RTS

; 06: Handle single actor targeting in main menu
C31DE8:  JSR C33548      ; Redraw time
         LDA $09         ; Pushing B?
         BPL C31DFD      ; Branch if not
         LDA #$05        ; Blinker: Off
         TRB $46         ; Actor cursor: Off
         LDA #$03        ; C3/1D94
         STA $26         ; Next: Main menu
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle MT mode switch
C31DFD:  BIT #$02        ; Pushing left?
         BEQ C31E1F      ; Branch if not
         LDA $25         ; Selected menu
         CMP #$02        ; Equip?
         BEQ C31E0D      ; Branch if so
         CMP #$03        ; Relic?
         BNE C31E1F      ; Branch if not
C31E0D:  JSR C30EA3      ; Sound: Cursor
         LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         LDA #$37        ; C3/1EB5
         STA $26         ; Next: Target all
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         JMP C3089F      ; Create blinkers

; Fork: Handle A
C31E1F:  LDA $08         ; Pushing A?
         BPL C31DE7      ; Exit if not
         LDA $4B         ; Cursor slot
         STA $28         ; Set member slot
         JSR C31E4E      ; Can open menu?
         BCS C31E42      ; Fail if not
         TDC             ; Clear A
         LDA $25         ; Menu to open
         TAX             ; Index it
         LDA.L C31E49,X  ; Init command
         STA $27         ; Put in queue
         STZ $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Fork: Inaccessible menu
C31E42:  JMP C3B66F      ; Buzzer + Mosaic

; Initialization commands for actor menus
C31E49:  db $FF          ; Blank
         db $09          ; Skills
         db $35          ; Equip
         db $58          ; Relic
         db $0B          ; Status

; Determine if actor-related menu is accessible
C31E4E:  TDC             ; Clear A
         LDA $25         ; Menu to open
         DEC A           ; Skills?
         BEQ C31E89      ; Branch if so
         DEC A           ; Equip?
         BEQ C31E5F      ; Branch if so
         DEC A           ; Relic?
         BEQ C31E74      ; Branch if so

; Fork: Set to open menu
C31EB3:  CLC             ; Mark success
         RTS

; Fork: Equip
C31E5F:  LDA $28         ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; Actor's address
         LDA $00,X       ; Actor
         CMP #$0D        ; Umaro or guest?
         BCS C31EB1      ; Fail if so
         BRA C31E9C      ; Check if dead

; Fork: Relic
C31E74:  LDA $28         ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; Actor's address
         LDA $00,X       ; Actor
         CMP #$0E        ; Guest?
         BCS C31EB1      ; Fail if so
         BRA C31E9C      ; Check if dead

; Fork: Skills
C31E89:  JSR C34D3D      ; Set skill colors
         LDA #$24        ; Palette: Gray
         LDX #$0006      ; 1st: Dance
C31E90:  CMP $79,X       ; Grayed skill?
         BNE C31E9C      ; Branch if not
         DEX             ; Skill slot -1
         BPL C31E90      ; Loop till Espers
         BRA C31EB1      ; Play buzzer

; Fork: Check if dead
C31E9C:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; Actor's address
         LDA $14,X       ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BEQ C31EB3      ; Allow if none

; Fork: Set to play buzzer
C31EB1:  SEC             ; Mark failure
         RTS

; 37: Handle multitargeting in main menu
C31EB5:  JSR C33548      ; Redraw time
         LDA $09         ; No-autofire keys
         BIT #$81        ; Using B or right?
         BEQ C31EE5      ; Branch if not
         JSR C32F98      ; Preload nav data
         JSR C307B0      ; Queue cursor OAM
         LDY #C32FC0     ; C3/2FC0
         JSR qanim0      ; Queue D-Pad fn
         JSR C311B0      ; Run anim queue
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         LDA #$06        ; C3/1DE8
         STA $26         ; Next: ST actor
         LDA #$08        ; Blinkers: Off
         TRB $46         ; Set menu flag
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle A
C31EE5:  LDA $08         ; Pushing A?
         BPL C31EB1      ; Exit if not
         STZ $26         ; Next: Fade-out
         LDA #$38        ; C3/1C32
         STA $27         ; Queue: Party gear
         JMP C30EB2      ; Sound: Click

; 08: Handle Item menu choice 1
C31EF7:  JSR desc_on     ; Description: On
         TDC             ; Clear A
         STA $2A         ; List type: Stock
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C31EB1      ; Exit if pushed
         JSR C37D22      ; Handle D-Pad
         JSR C382F1      ; Load description

; Fork: Handle B
C31F0C:  LDA $09         ; Pushing B?
         BPL C31F3B      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDY $4F         ; Cursor position
         STY $022F       ; To cursor memory
         LDA $4A         ; Scroll position
         STA $0231       ; To cursor memory
         JSR C37D80      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C31F2E      ; Branch if not
         LDY $0234       ; Former position
         STY $4D         ; Set as current
C31F2E:  JSR C37D86      ; Relocate cursor
         LDA #$17        ; C3/25F4
         STA $26         ; Next: Option list
         JSR C38385      ; Blank item count
         JMP C30F39      ; Queue its upload

; Fork: Handle A
C31F3B:  LDA $08         ; Pushing A?
         BPL C31F55      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; List slot
         STA $28         ; Set choice 1's
         LDA #$19        ; C3/2779
         STA $26         ; Next: Choice 2
         JMP C32F21      ; Create blinker

; Hi-fork: Pressed L on first page
C31F50:  STZ $50         ; List row: 1
         STZ $4E         ; Cursor row: 1
         SEC             ; Mark L/R usage
C31F55:  RTS

; Hi-fork: Pressed R on last page
C31F56:  LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         STA $4E         ; Set cursor row
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         STA $50         ; Set list row
         SEC             ; Mark L/R usage
         RTS

; Hi-fork: Do nothing
C31F62:  CLC             ; Mark no L/R use
         RTS

; Handle L and R for scrollable list
C31F64:  LDA $20         ; Scrolling now?
         BNE C31F62      ; Exit if so
         LDA $0A         ; Semi-auto keys
         BIT #$10        ; Pushing R?
         BEQ C31F93      ; Branch if not
         LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C31F56      ; Branch if so
         LDA $5C         ; Scroll limit
         SEC             ; Prepare SBC
         SBC $4A         ; Get rows left
         CMP $5A         ; Full page below?
         BCC C31F81      ; Branch if not
         LDA $5A         ; Rows per page
C31F81:  STA $E0         ; Set shift qty
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         STA $4A         ; Set scroll pos
         LDA $50         ; List row
         CLC             ; Prepare ADC
         ADC $E0         ; Add shift qty
         STA $50         ; Save changes
         BRA C31FB7      ; Redraw & Sound

; Fork: Handle L
C31F93:  BIT #$20        ; Pushing L?
         BEQ C31F62      ; Exit if not
         LDA $4A         ; On first page?
         BEQ C31F50      ; Branch if so
         CMP $5A         ; Full page above?
         BCC C31FA7      ; Branch if not
         LDA $5A         ; Rows per page
C31FA7:  STA $E0         ; Set shift qty
         LDA $4A         ; Scroll position
         SEC             ; Prepare SBC
         SBC $E0         ; Sub shift qty
         STA $4A         ; Save changes
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $E0         ; Sub shift qty
         STA $50         ; Save changes

; Fork: Redraw list, play sound effect
C31FB7:  JSR C30EA3      ; Sound: Cursor
         TDC             ; Clear A
         LDA $2A         ; List type
         ASL A           ; Double it
         TAX             ; Index it
         JSR (C31FC4,X)  ; Redraw list
         SEC             ; Mark L/R usage
         RTS

; Jump table for the above
C31FC4:  dw C31FD0       ; Inventory
         dw C31FD6       ; Magic
         dw C31FDC       ; Lore
         dw C31FE2       ; Rage
         dw C31FE8       ; Esper
         dw C31FEE       ; Gear

; Redraw inventory for page swap (Item, Colosseum, Sell)
C31FD0:  JSR C37E95      ; Load V-shift data
         JMP C37F88      ; Draw inventory

; Redraw Magic list for page swap
C31FD6:  JSR C34E2D      ; Load V-shift data
         JMP C34F87      ; Draw spell list

; Redraw Lore list for page swap
C31FDC:  JSR C34E2D      ; Load V-shift data
         JMP C3523C      ; Draw Lore list

; Redraw Rage list for page swap
C31FE2:  JSR C34E2D      ; Load V-shift data
         JMP C353A7      ; Draw Rage list

; Redraw Esper list for page swap
C31FE8:  JSR C34E2D      ; Load V-shift data
         JMP C3546C      ; Draw esper list

; Redraw gear list for page swap (Equip, Relic)
C31FEE:  JSR C39520      ; Load V-shift data
         JMP C39CAC      ; Draw item list

; 0A: Sustain Skills menu
C31FF4:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C34B56      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C3200F      ; Branch if not
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle A
C3200F:  LDA $08         ; Pushing A?
         BPL C3201C      ; Branch if not
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         BRA C3208A      ; Invoke submenu

; Fork: Handle L and R, prepare for menu reset
C3201C:  LDA #$09        ; Init cmd: C3/1B5B

; Handle member switching with L or R (excludes Status menu)
C32022:  STA $E0         ; Set init command
         LDA $B5         ; Mosaic settings
         AND #$F0        ; Mosaic enabled?
         BNE C32089      ; Exit if so
         LDX #$0001      ; Swap order: R
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE .go         ; Branch if so
         BIT #$20        ; Pushing L?
         BEQ C32089      ; Exit if not
         LDX #$FFFF      ; Swap order: L
.go      STX $F3         ; Set swap order
         LDA $25         ; Submenu
         CMP #$03        ; Relic?
         BNE C3203F      ; Branch if not
         JSR C39EEB      ; Handle Reequip
         BCC C3203F      ; If not triggered
         JMP C30EA3      ; Sound: Cursor

; Fork: Switch to next or preceding member
C3203F:  TDC             ; Clear A
         LDA $28         ; Current member
         CLC             ; Prepare ADC
         ADC $F3         ; Go L or R
         AND #$03        ; Wrap if needed
         STA $28         ; Save changes
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C3203F      ; Skip if so
         JSR C31E4E      ; Can access menu?
         BCS C3203F      ; Skip if not
         LDA $E0         ; Init command
         STA $26         ; Set menu mode
         JMP C30EA3      ; Sound: Cursor
C32089:  RTS

; Initialize selected Skills submenu if accessible
C3208A:  TDC             ; Clear A
         LDA $4B         ; Chosen menu
         TAX             ; Index it
         LDA $79,X       ; Name's color
         CMP #$20        ; User's color?
         BNE C3209E      ; Fail if not
         JSR C30EB2      ; Sound: Click
         STZ $4A         ; List scroll: 0
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         TXA             ; Chosen menu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C320A5,X)  ; Invoke menu

; Fork: Play buzzer
C3209E:  JMP C3B66F      ; Buzzer + Mosaic

; Jump table for the above
C320A5:  dw C320B3       ; Espers
         dw C3211C       ; Magic
         dw C320EE       ; SwdTech
         dw C32105       ; Blitz
         dw C3216E       ; Lore
         dw C321A6       ; Rage
         dw C321DE       ; Dance

; Initialize Espers menu
C320B3:  JSR C35452      ; Draw espers, etc.
         JSR C32EEB      ; Create blinker
C320B_:  LDA #$68        ; Y: 104
         LDY #$1000      ; V-Speed: 16 px
         JSR C3091F      ; Create scrollbar
         LDA #$06        ; Top row: Golem's
         STA $5C         ; Set scroll limit
         LDX #$0208      ; Onscreen rows: 8
         STX $5A         ; Onscreen cols: 2
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         LDA #$1E        ; C3/28D3
         STA $26         ; Next: Sustain menu
         LDY #C34C27     ; C3/4C27
         JSR C305FE      ; Load navig data
         JMP C34C21      ; Relocate cursor

; Initialize SwdTech menu
C320EE:  JSR C34BCE      ; Load navig data
         JSR C34BD7      ; Relocate cursor
         LDA #$3E        ; C3/298E
         STA $26         ; Next: Sustain menu
         JMP C352D7      ; Draw techs, etc.

; Initialize Blitz menu
C32105:  JSR C34BCE      ; Load navig data
         JSR C34BD7      ; Relocate cursor
         LDA #$33        ; C3/2977
         STA $26         ; Next: Sustain menu
         JMP C355D4      ; Draw inputs, etc.

; Initialize Magic menu
C3211C:  LDA #$1A        ; C3/27E2
         STA $26         ; Next: Sustain menu
         JSR C32130      ; Create scrollbar
         JSR C32148      ; Load nav data, etc.
         JSR C32158      ; Draw spells, etc.
         JMP C30F4D      ; Queue BG3 upload

; Create scrollbar for Magic menu
C32130:  LDA #$68        ; Y: 104
         LDY #$050D      ; V-Speed: 5.05 px
         JMP C3091F      ; Create scrollbar

; Load navigation data for Magic menu; position cursor
C32148:  JSR C34B82      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C32155      ; Branch if not
         JSR C30E0A      ; Restore cursor
C32155:  JMP C34B8B      ; Relocate cursor

; Switch to Magic menu, create portrait, draw spells and "MP…"
C32158:  LDA #$13        ; Top row: Sleep's
         STA $5C         ; Set scroll limit
         LDX #$0208      ; Onscreen rows: 8
         STX $5A         ; Onscreen cols: 2
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C34D7F      ; Draw spells, etc.
         JMP C351C6      ; Draw MP cost

; Initialize Lore menu
C3216E:  LDA #$68        ; Y: 104
         LDY #$0600      ; V-Speed: 6 px
         JSR C3091F      ; Create scrollbar
         LDY #C34C03     ; C3/4C03
         JSR C305FE      ; Load navig data
         JSR C34BFD      ; Relocate cursor
         LDA #$10        ; Top row: Dischord
         STA $5C         ; Set scroll limit
         LDX #$0108      ; Onscreen rows: 8
         STX $5A         ; Onscreen cols: 1
         LDA #$1B        ; C3/288A
         STA $26         ; Next: Sustain menu
         JMP C351F9      ; Draw lores, etc.

; Initialize Rage menu
C321A6:  LDA #$68        ; Y: 104
         LDY #$00CC      ; V-Speed: 0.8 px
         JSR C3091F      ; Create scrollbar
         LDY #C34C5B     ; C3/4C5B
         JSR C305FE      ; Load navig data
         JSR C34C55      ; Relocate cursor
         LDA #$78        ; Top row: Tap Dancer
         STA $5C         ; Set scroll limit
         LDX #$0208      ; Onscreen rows: 8
         STX $5A         ; Onscreen cols: 2
         LDA #$1D        ; C3/28BA
         STA $26         ; Next: Sustain menu
         JMP C35391      ; Draw rages, etc.

; Initialize Dance menu
C321DE:  JSR C34BCE      ; Load navig data
         JSR C34BD7      ; Relocate cursor
         LDA #$1C        ; C3/22AA
         STA $26         ; Next: Sustain menu
         JMP C35774      ; Draw dances, etc.

; 0C: Sustain Status menu
C321F5:  JSR C30F39      ; Set to redraw cmds
         LDX #$0001      ; Swap order: R
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE .go         ; Branch if so
         BIT #$20        ; Pushing L?
         BEQ C32244      ; Branch if not
         LDX #$FFFF      ; Swap order: L
.go      STX $E0         ; Set swap order
         LDA $28         ; Member slot
         PHA             ; Set former slot

; Fork: Switch to next or preceding member
C32202:  TDC             ; Clear A
         LDA $28         ; Member slot
         CLC             ; Prepare ADC
         ADC $E0         ; Go L or R
         AND #$03        ; Wrap if needed
         STA $28         ; Save changes
         TAX             ; Index slot
         LDA $69,X       ; Nobody there?
         BMI C32202      ; Skip slot if so
         PLA             ; Former member
         CMP $79         ; Matches new one?
         BEQ C32218      ; Skip sound if so
         JSR C30EA3      ; Sound: Cursor
C32218:  JSR C31C5D      ; Init cursor data
         JMP C35D83      ; Swap actor info

; Fork: Handle B
C32244:  LDA $09         ; Pushing B?
         BPL C32254      ; Branch if not
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor
C32253:  RTS

; Fork: Handle Gogo
C32254:  JSR gogo1       ; Actor = Gogo?
         BNE C32253      ; Exit if not
         JSR C33705      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C32253      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         JSR C32D03      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         ADC $E7         ; Add cursor slot
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $16,X       ; Chosen command
         CMP #$12        ; Mimic?
         BEQ C32253      ; Exit if so
         JSR C32F06      ; Create blinker
         LDA $4E         ; Cursor row
         STA $64         ; Set altered slot
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$6A        ; C3/63A7
         STA $27         ; Queue: Shifted menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Shift screen
         LDY #C36412     ; C3/6412
         JSR C305FE      ; Load navig data
         LDA $7E9D89     ; Command list size
         STA $54         ; Set number of rows
         JMP C3640C      ; Relocate cursor

; 0E: Sustain Config menu
C322C5:  JSR C30EE9      ; Queue list upload
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C322E0      ; Branch if not
         LDA $4E         ; Cursor row
         CMP #$08        ; On Controller?
         BNE C322E0      ; Branch if not
         LDA #$50        ; C3/3A00
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle upward scrolling
C322E0:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C322FA      ; Branch if not
         LDA $4E         ; On top row?
         BNE C322FA      ; Branch if not
         LDA $4A         ; On first page?
         BEQ C322FA      ; Branch if so
         LDA #$51        ; C3/3A21
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle B and D-Pad
C322FA:  LDA $4A         ; On first page?
         BEQ C32303      ; Branch if so
         JSR C33884      ; Handle P2 D-Pad
         BRA C32306      ; Skip a line
C32303:  JSR C3385E      ; Handle P1 D-Pad
C32306:  LDA $09         ; Pushing B?
         BPL C32316      ; Branch if not
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle left and right
C32316:  LDA $0B         ; Semi-auto keys
         BIT #$03        ; Using left/right?
         BEQ C32325      ; Branch if not
         JMP C33D2F      ; Change settings

; Fork: Handle A
C32325:  LDA $08         ; Pushing A?
         BMI C32331      ; Branch if so

; Fork: Handle L and R
C3232E:  JMP C323EC      ; Handle L and R

; Fork: Handle clicked option
C32331:  LDA $4E         ; Cursor row
         STA $5F         ; Set return row
         LDA $4A         ; On page 2?
         BNE C32342      ; Branch if so
         LDA $4B         ; Cursor slot
         CMP #$03        ; On Cmd.Set?
         BEQ C32368      ; Branch if so
         CMP #$08        ; On Controller?
         BEQ C32379      ; Branch if so
         RTS

; Fork: Handle click on page 2
C32342:  LDA $4B         ; Cursor slot
         CMP #$02        ; In color area?
         BCS C32388      ; Branch if so
         RTS

; Handle click on "Short" option
C32368:  LDA $1D4D       ; Short cmd set?
         BPL C323EB      ; Exit if not
         LDA #$47        ; C3/42C2
         STA $27         ; Queue cmd menu
         STZ $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Handle click on "Multiple" option
C32379:  LDA $1D54       ; Multiplayer mode?
         BPL C323EB      ; Exit if not
         LDA #$4B        ; C3/46AD
         STA $27         ; Queue joypad menu
         STZ $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Handle color resetting in options
C32388:  JSR C30EB2      ; Sound: Click
         LDA $1D54       ; Game options
         AND #$38        ; Get viewed color
         BEQ C3239B      ; Branch if font
         JSR C323A7      ; Reset skin colors
         JSR C33A87      ; Refresh skin
         JMP C341C3      ; Redraw RGB info

; Fork: Reset font color
C3239B:  LDY #$7FFF      ; Color: White
         STY $1D55       ; Put in options
         JSR C33F99      ; Put in palettes
         JMP C341C3      ; Redraw RGB info

; Reset skin palette
C323A7:  TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         PHA             ; Memorize it
         LDY #$0020      ; ROM data size
         JSR mul16       ; Skin x size
         PLA             ; Wallpaper
         PHX             ; Save ROM index
         LDY #$000E      ; RAM data size
         JSR mul16       ; Skin x size

; Fork: Load skin palette
C323C9:  LDY #$312B      ; 7E/312B
         STY $2181       ; Set WRAM LBs
         TXY             ; RAM index
         PLX             ; ROM index
         SEP #$20        ; 8-bit A
         LDA #$0E        ; Colors: 7
C323DB:  PHA             ; Save counter
         LDA $ED1C02,X   ; Color data
         STA $1D57,Y     ; Put in options
         STA $2180       ; Put in palette
         INX             ; ROM index +1
         INY             ; RAM index +1
         PLA             ; Bytes left
         DEC A           ; One less left
         BNE C323DB      ; Loop till last
C323EB:  RTS

; Handle L and R in Config menu
C323EC:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BEQ C323EB      ; Exit if not
         JSR C30EA3      ; Sound: Cursor
         LDA $4A         ; On first page?
         BNE C32406      ; Branch if not
         INC $4A         ; Page: 2nd
         JMP C339EA      ; Switch screens

; Fork: On page 2
C32406:  STZ $4A         ; Page: 1st
         JMP C339F5      ; Switch screens

; 0F: Handle Order menu choice 1
C3240C:  JSR C33548      ; Redraw time
         JSR C36989      ; Set SRAM party
         LDA $09         ; No-autofire keys
         BIT #$81        ; Using B or right?
         BEQ C32437      ; Branch if not
C3241E:  LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off
         TRB $46         ; Order cursor: Off
         LDA #$03        ; C3/1D94
         STA $27         ; Queue: Main menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle A
C32437:  LDA $08         ; Pushing A?
         BPL C323EB      ; Exit if not
         LDA $4B         ; Selected slot
         STA $28         ; Set choice 1
         LDA #$10        ; C3/2453
         STA $26         ; Next: Choice 2
         JSR C32F21      ; Create blinker
         JSR C32FB1      ; Unlock all slots
         JMP C30EB2      ; Sound: Click

; 10: Handle Order menu choice 2
C32453:  JSR C33548      ; Redraw time
         LDA $09         ; Pushing B?
         BPL C3246F      ; Branch if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$0F        ; C3/240C
         STA $26         ; Next: Choice 1
         JSR C32F98      ; Lock empty slots
         LDA $28         ; Old cursor row
         STA $4E         ; Set as current
         JMP C30EA9      ; Sound: Cursor

; Fork: Change row
C3246F:  LDA $08         ; Pushing A?
         BPL C324A8      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $28         ; First selection
         CMP $4B         ; Matches second?
         BNE C32491      ; Swap if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$12        ; C3/2537
         STA $26         ; Next: Wait
         JSR C32E10      ; Set row, scroll
         LDY #$000C      ; Frames: 12
         STY $20         ; Set wait timer
         JMP C32F98      ; Lock empty slots

; Fork: Switch members
C32491:  LDA #$10        ; Cursor: Freeze
         TRB $46         ; Set menu flag
         LDA #$0C        ; Cursor: Blank
         TRB $45         ; Unhide chars: N
         JSR C33582      ; Queue swap anim
         LDA #$18        ; Frames: 24
         STA $22         ; Set anim timer
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$11        ; C3/24A9
         STA $26         ; Next: Sustain swap
C324A8:  RTS

; 11: Switch members in Order menu
C324A9:  JSR C33548      ; Redraw time
         LDA $22         ; Timer expired?
         BEQ C324E0      ; Finalize if so
         CMP #$0C        ; Unhide point?
         BNE C324ED      ; Exit if not
         JSR C324F8      ; Swap battle pads
         JSR C32DD1      ; Swap actor info
         JSR C324EE      ; Clear icons/faces
         JSR C36A15      ; Erase party info
         JSR C33193      ; Redraw party info
         JSR C30DBA      ; Swap saved cursors
         JSR C30EFD      ; Queue stats upload
         JSR C32F98      ; Lock empty slots
         JSR C311B0      ; Run anim queue
         JSR C31368      ; Refresh screen
         LDA #$08        ; Unhide members: Y
         TSB $45         ; Set menu flag
         RTS

; Fork: Restore control
C324E0:  LDA #$0F        ; C3/240C
         STA $26         ; Next: Choice 1
         LDA #$10        ; Cursor: Unfreeze
         TSB $46         ; Set menu flag
         LDA #$04        ; Show cursor: Y
         TSB $45         ; Set menu flag
C324ED:  RTS

; Delete all portraits and status icons
C324EE:  JSR C32E3C      ; Portraits: Erase
         LDA #$01        ; Icons: Delete
         TRB $47         ; Set menu flag
         JMP C311B0      ; Run anim queue

; Swap assigned joypad for switched members
C324F8:  TDC             ; Clear A
         TAX             ; Member slot: 1
         STX $E0         ; Char 1+2: Pad 1
         STX $E2         ; Char 3+4: Pad 1
         LDA $1D4F       ; Game options
         CLC             ; Prepare ROR
C32502:  ROR A           ; Member's joypad
         BCC C32507      ; Skip if Pad 1
         INC $E0,X       ; Assign Pad 2
C32507:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C32502      ; Loop if not
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $E0,X       ; Member B's pad
         PHA             ; Memorize it
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA $E0,X       ; Member A's pad
         STA $E6         ; Memorize it
         PLA             ; Member B's pad
         STA $E0,X       ; Set as A's
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $E6         ; Member A's pad
         STA $E0,X       ; Set as B's
         LDA $E3         ; Member 4's pad
         ASL A           ; Put in bit 1
         ADC $E2         ; Add member 3's
         ASL A           ; Put in bit 1-2
         ADC $E1         ; Add member 2's
         ASL A           ; Put in bit 1-3
         ADC $E0         ; Add member 1's
         STA $1D4F       ; Update options
         RTS

; 12: Wait while member changes row
C32537:  LDY $20         ; Timer expired?
         BNE C3253F      ; Exit if not
         LDA #$0F        ; C3/240C
         STA $26         ; Next: Choice 1
C3253F:  RTS

; 14: Sustain Save menu
C32540:  LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set save slot
         JSR C31903      ; Refresh actors
         JSR C315AA      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C3255D      ; Branch if not
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle A
C3255D:  LDA $08         ; Pushing A?
         BPL C3253F      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $91,X       ; Blank file?
         BNE C32580      ; Branch if not
         LDA $66         ; Save slot
         STA $021F       ; Link to game
         JSR C325DF      ; Save game
         LDA #$13        ; Menu init cmd
         STA $27         ; Queue Save menu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         JMP C30EB9      ; Sound: Save

; Fork: Invoke confirmation menu
C32580:  JSR C318AC      ; Back up SRAM data
         LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set save slot
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C36989      ; Set SRAM party
         LDA #$15        ; C3/1CE3
         STA $27         ; Queue submenu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; 16: Sustain save confirmation
C3259D:  JSR C315DA      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BMI C325C2      ; Abort if so
         LDA $08         ; Pushing A?
         BPL C325DE      ; Exit if not
         LDA $4B         ; Chose "No"?
         BNE C325C7      ; Abort if so
         LDA $66         ; Save slot
         STA $021F       ; Link to game
         JSR C325DF      ; Save game
         LDA #$13        ; C3/1CA0
         STA $27         ; Queue Save menu
         STZ $26         ; Next: Fade-out
         JMP C30EB9      ; Sound: Save

; Fork: Pushing B
C325C2:  JSR C30EA9      ; Sound: Cursor
         BRA C325CA      ; Skip a line

; Fork: Chose "No"
C325C7:  JSR C30EB2      ; Sound: Click
C325CA:  JSR C318C1      ; Restore SRAM
         JSR C36915      ; And party info
         JSR C36989      ; Set SRAM party
         LDA #$13        ; C3/1CA0
         STA $27         ; Queue Save menu
         STZ $26         ; Next: Fade-out
         LDA $66         ; File number
         STA $0224       ; Set last viewed
C325DE:  RTS

; Restore SRAM block and record game data
C325DF:  JSR C318C1      ; Restore SRAM
         JSR C36915      ; And party info
         JSR C36989      ; Set SRAM party
         REP #$20        ; 16-bit A
         INC $1DC7       ; Save count +1
         SEP #$20        ; 8-bit A
         LDA $66         ; File number
         JMP C3151D      ; Save game data

; 17: Handle Item menu options
C325F4:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30EFD      ; Queue stock upload
         JSR C37D8C      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C32611      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
C32611:  LDA $08         ; Pushing A?
         BPL C325DE      ; Exit if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32626,X)  ; Handle option

; Jump table for the above
C32626:  dw C3262C       ; USE
         dw C3267C       ; ARRANGE
         dw C3268E       ; RARE

; Handle "USE" selection in Item menu
C3262C:  JSR C37D1C      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C3263B      ; Branch if not
         JSR C30DAC      ; Restore cursor
         BRA C3264B      ; Skip cursor reset
C3263B:  LDY $4D         ; Cursor position
         STY $4F         ; Set as list loc
         LDA $0231       ; Old scroll pos
         STA $4A         ; Set as current
         CLC             ; Prepare ADC
         ADC $50         ; Add list V-Slot
         STA $50         ; Set list V-Slot
C3264B:  JSR C37D25      ; Relocate cursor
         JSR C3BC02      ; Draw list; bar
         JSR C382F1      ; Desc; item count
         JSR C30F39      ; Queue BG3 upload
         JSR C31368      ; Refresh screen
         JSR C38510      ; Next: Choice 1
         LDY #C3A80E     ; C3/A80E
         JMP qanim0      ; Queue desc update

; Handle "ARRANGE" selection in Item menu
C3267C:  JSR C36A15      ; Hide inventory
         JSR C326B8      ; Move inventory
         JSR C326E0      ; Sort inventory
         JSR C37F88      ; Redraw inventory
         JSR C37D80      ; Load navig data
         JMP C31F2E      ; Move cursor, etc.

; Initialize rare item menu
C3268E:  LDY #C37D53     ; C3/7D53
         JSR C305FE      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C3269D      ; Branch if not
         LDY $0232       ; Former position
         STY $4D         ; Set as current
C3269D:  JSR C37D4D      ; Relocate cursor
         JSR C3838B      ; Draw item list
         JSR C31B99      ; Queue desc anim
         JSR C38339      ; Get desc/draw count
         JSR C30F39      ; Queue count upload
         JSR C31368      ; Refresh screen
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$18        ; C3/2741
         STA $26         ; Next: Sustain menu
         RTS

; Relocate inventory for sorting, delete original
C326B8:  LDX #$00FF      ; Item slot: 256
C326BA:  LDA $1869,X     ; Item in slot
         STA $7EAA8D,X   ; Put in buffer
         LDA #$FF        ; Empty item
         STA $1869,X     ; Clear original
         LDA $1969,X     ; Item quantity
         STA $7EAB8D,X   ; Put in buffer
         STZ $1969,X     ; Clear original
         DEX             ; Item slot -1
         BPL C326BA      ; Loop till < 0
         RTS

; Sort inventory based on item icons
C326E0:  TDC             ; Clear A
         TAY             ; Item slot: 1
         TAX             ; Icon index: 0
C326E3:  LDA.L C326F5,X  ; Item icon
         PHX             ; Save index
         STA $E0         ; Set class
         JSR C32706      ; Get such items
         PLX             ; Icon index
         INX             ; Index +1
         CPX #$0011      ; Done 17 icons?
         BNE C326E3      ; Loop if not
         RTS

; Copy all items with given icon from buffer to inventory
C32706:  TDC             ; Clear A
         TAX             ; Buffer slot: 1
C32708:  PHX             ; Save buffer slot
         LDA $7EAA8D,X   ; Item in slot
         CMP #$FF        ; None?
         BEQ C32739      ; Skip if so
         XBA             ; Put in B
         LDA.B #!itm_ns  ; Name data size
         JSR mul8        ; Item x size
         TAX             ; Index product
         LDA.L !itm_np,X ; Item icon
         CMP $E0         ; Sought type?
         BNE C32739      ; Skip if not
         PLX             ; Buffer slot
         LDA $7EAA8D,X   ; Item in slot
         STA $1869,Y     ; Put in stock
         LDA $7EAB8D,X   ; Item quantity
         STA $1969,Y     ; Put in stock
         INY             ; Stock slot +1
         BRA C3273A      ; Skip a line
C32739:  PLX             ; Buffer slot
C3273A:  INX             ; Buffer slot +1
         CPX #$0100      ; Done all 256?
         BNE C32708      ; Loop if not
C32740:  RTS

; 18: Sustain rare item menu
C32741:  JSR desc_on     ; Description: On
         JSR C30EFD      ; Queue list upload
         JSR C37D4A      ; Handle D-Pad
         JSR C38339      ; Get desc/draw count
         LDA $09         ; Pushing B?
         BPL C32740      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$17        ; C3/25F4
         STA $26         ; Next: Option list
         LDY $4D         ; Cursor position
         STY $0232       ; To cursor memory
         JSR C37D80      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C3276F      ; Branch if not
         LDY $0234       ; Former position
         STY $4D         ; Set as current
C3276F:  JSR C37D86      ; Relocate cursor
         JSR C38385      ; Blank item count
         JMP C30F39      ; Queue its upload

; 19: Handle Item menu choice 2
C32779:  JSR C30EFD      ; Queue list upload
         JSR C37D22      ; Handle D-Pad
         JSR C382F1      ; Load description
         LDA $09         ; Pushing B?
         BPL C32794      ; Branch if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JSR C38510      ; Next: Choice 1
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle A
C32794:  LDA $08         ; Pushing A?
         BPL C32740      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $28         ; First selection
         CMP $4B         ; Matches second?
         BNE C327AA      ; Swap them if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JMP C38497      ; Handle item

; Fork: Switch items
C327AA:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JSR C38510      ; Next: Choice 1
         TDC             ; Clear A
         LDA $28         ; Slot A
         TAY             ; Index it
         LDA $1969,Y     ; Quantity A
         PHA             ; Save it
         LDA $1869,Y     ; Item A
         PHA             ; Save it
         LDA $4B         ; Slot B
         TAX             ; Index it
         LDA $1869,X     ; Item B
         STA $1869,Y     ; Replace A
         PLA             ; Item A
         STA $1869,X     ; Replace B
         LDA $1969,X     ; Quantity B
         STA $1969,Y     ; Replace A
         PLA             ; Quantity A
         STA $1969,X     ; Replace B
         JMP C37F88      ; Redraw list

; 1A: Sustain Magic menu
C327E2:  JSR desc_on     ; Description: On
         LDA #$01        ; List type: Magic
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         LDA $021E       ; Frame counter
         ROR A           ; Even value?
         BCC C327F8      ; Favor desc if so
         JSR C30F75      ; Queue cost upload
         BRA C327FB      ; Skip a line
C327F8:  JSR C3A991      ; Queue desc upload
C327FB:  JSR C31F64      ; Handle L and R
         BCS C32854      ; Exit if pushed
         JSR C34B88      ; Handle D-Pad
         JSR C356E5      ; Load description
         JSR C351C6      ; Draw MP cost

; Fork: Handle Y
C32809:  LDA $09         ; No-autofire keys
         ASL A           ; Pushing Y?
         BPL C32822      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $9E         ; MP display switch
         EOR #$FF        ; Toggle it
         STA $9E         ; Save changes
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C34F1C      ; Build spell list
         JMP C34F87      ; Draw spell list

; Fork: Handle A
C32822:  LDA $08         ; Pushing A?
         BPL C32855      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Spell slot
         TAX             ; Index it
         LDA $7E9E09,X   ; Spell palette
         CMP #$20        ; User's color?
         BNE C32862      ; Fail if not
         JSR C30EB2      ; Sound: Click
         LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         LDA $4B         ; Cursor slot
         STA $99         ; Set spell slot
         JSR C32D13      ; Spell
         CMP #$2A        ; Warp?
         BEQ C32874      ; Branch if so
         LDA #$3A        ; C3/2A65
         STA $27         ; Queue usage menu
         STZ $26         ; Next: Fade-out
C32854:  RTS

; Fork: Handle B
C32855:  LDA $09         ; Pushing B?
         BPL C32854      ; Exit if not
         JSR C30EFD      ; Queue BG1 upload
         JMP C329A5      ; Exit submenu

; Fork: Unusable spell
C32862:  JMP C3B66F      ; Buzzer + Mosaic

; Fork: Warp
C32874:  LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C32862      ; Fail if not
         LDA #$03        ; Event: Warp
C3287D:  STA $0205       ; Set aftereffect
         JSR C32CEA      ; Lower caster's MP
         JMP fdexit      ; Queue menu exit

; 1B: Sustain Lore menu
C3288A:  JSR desc_on     ; Description: On
         LDA #$02        ; List type: Lores
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C32907      ; Exit if pushed
         JSR C34BFA      ; Handle D-Pad
         JSR C356EB      ; Load description
         LDA $09         ; Pushing B?
         BPL C32907      ; Exit if not
         JMP C329A5      ; Leave submenu

; 1C: Sustain Dance menu
C328AA:  JSR C30EFD      ; Queue list upload
         JSR C34BD4      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C32907      ; Exit if not
         JMP C329A5      ; Leave submenu

; 1D: Sustain Rage menu
C328BA:  LDA #$03        ; List type: Rages
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C32907      ; Exit if pushed
         JSR C34C52      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C32907      ; Exit if not
         JMP C329A5      ; Leave submenu

; 1E: Handle esper selection
C328D3:  JSR desc_on     ; Description: On
         LDA #$04        ; List type: Espers
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C32907      ; Exit if pushed
         JSR C34C1E      ; Handle D-Pad
         JSR C356DF      ; Load description
         LDA $08         ; Pushing A?
         BPL C3291B      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C3BFC2      ; Chosen esper
         CMP #$FF        ; Empty slot?
         BEQ C32908      ; Unequip if so
         STA $99         ; Memorize esper
         JSR C35897      ; Init submenu
         LDA #$4D        ; C3/58CE
         STA $26         ; Next: Data menu
C32907:  RTS

; Fork: Unequip esper
C32908: ;LDA #$FF        ; Value for empty
         STA $E0         ; Set esper to equip
         JSR C32929      ; Clear esper held
         JSR C3546C      ; Redraw esper list
         JSR C30F11      ; Queue stats upload
         JSR C31368      ; Refresh held esper
         JMP C30EFD      ; Queue list upload

; Fork: Handle B
C3291B:  LDA $09         ; Pushing B?
         BPL C32907      ; Exit if not
         LDA #$08        ; Blinker: Off
         TRB $46         ; Set menu flag
         BRA C329A5      ; Leave submenu

; Equip and draw selected esper
C32929:  JSR C32D03      ; Actor's address
         LDA $E0         ; Chosen esper
         STA $001E,Y     ; Assign to actor
         JMP C34F08      ; Draw it by actor

; 34: Wait while showing who holds esper
C3293A:  LDY $20         ; Timer expired?
         BNE C32907      ; Exit if not
         LDY #$40CD      ; Tilemap ptr
         JSR C33519      ; Set position
         LDY #$001B      ; Spaces: 27
         JSR spacedr     ; Blank message
         JMP C35913      ; Exit submenu

; 39: Sustain party gear overview
C32966:  LDA $09         ; Pushing B?
         BPL C3298D      ; Exit if not
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; 33: Sustain Blitz menu
C32977:  JSR desc_on     ; Description: On
         JSR C30EFD      ; Queue list upload
         JSR C34BD4      ; Handle D-Pad
         JSR C35715      ; Load description
         LDA $09         ; Pushing B?
         BMI C329A5      ; Return if so
C3298D:  RTS

; 3E: Sustain SwdTech menu
C3298E:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         JSR C30EFD      ; Queue list upload
         JSR C34BD4      ; Handle D-Pad
         JSR C35700      ; Load description
         LDA $09         ; Pushing B?
         BPL C3298D      ; Exit if not

; Return to Skills menu
C329A5:  JSR C30EA9      ; Sound: Cursor
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         LDA #$0A        ; C3/1FF4
         STA $26         ; Next: Skills menu
         JSR C34D27      ; Erase spell list
         JSR C34B50      ; Load navig data
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         JSR C34B59      ; Relocate cursor
         JMP C35807      ; Remove portrait

; 21: Sustain Load menu
C329C2:  LDA $4B         ; Cursor slot
         STA $66         ; Set save slot
         JSR C31903      ; Refresh actors
         JSR C315BE      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3298D      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; On new game?
         BEQ C32A07      ; Branch if so
         STA $66         ; Set save slot
         DEC A           ; Now 0-2
         ASL A           ; Double it
         TAX             ; Index it
         LDY $91,X       ; Blank file?
         BEQ C32A00      ; Fail if so
         JSR C318AC      ; Back up SRAM data
         LDA $66         ; Chosen save file
         STA $0224       ; Set last viewed
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C36989      ; Set SRAM party
         JSR C31595      ; Move timer data
         LDA #$22        ; C3/1D51
         STA $27         ; Queue confirm menu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Fork: Blank file
C32A00:  JMP C3B66F      ; Buzzer + Mosaic

; Fork: New game
C32A07:  JSR C32A21      ; Reset play time
         LDA #$01        ; Save file: 1st
         STA $0224       ; Set last viewed
         STZ $021F       ; Game's file: None
         STZ $0205       ; Set new game mode
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Reset play time
C32A21:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $021B       ; Zero hours, mins
         STY $021D       ; Zero secs, frames
         RTS

; 23: Sustain load confirmation
C32A2A:  JSR C315DA      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BMI C32A58      ; Abort if so
         LDA $08         ; Pushing A?
         BPL C32A64      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Chose "No"?
         BNE C32A5B      ; Abort if so
         LDY $1863       ; File's hrs, mins
         STY $021B       ; Set as current
         LDA $1865       ; File's seconds
         STA $021D       ; Set as current
         LDA $66         ; Loaded file
         STA $021F       ; Link to game
         JMP fdexit      ; Queue menu exit

; Fork: Chose "No"
C32A58:  JSR C30EA9      ; Sound: Cursor
C32A5B:  JSR C318C1      ; Restore SRAM
         LDA #$20        ; C3/1D03
         STA $27         ; Queue Load menu
         STZ $26         ; Next: Fade-out
C32A64:  RTS

; 3A: Initialize spell usage menu
C32A65:  LDA #$40        ; No cursor memory
         TSB $45         ; Set menu flag
         JSR C32A76      ; Init variables
         JSR C35812      ; Draw menu
         JSR C307B0      ; Queue cursor OAM
         LDA #$3B        ; Queue: Sustain menu
         BRA C32AA5      ; Next: Fade-in

; Initialize variables for spell or item usage menu
C32A76:  JSR C3352F      ; Reset/Stop stuff
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue Win1 HDMA
         JSR C30F89      ; Null VRAM ptr
         JSR C36904      ; Reset BGs' X/Y
         JSR C31BA8      ; Load portraits
;        LDA #$03        ; 64x64 at $0000
;        STA $2107       ; Set BG1 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C32F98      ; Preload nav data
         LDY #C32FC0     ; C3/2FC0
         JMP qanim0      ; Queue D-Pad fn

; Set queued menu command, trigger fade-in
C32AA5:  STA $27         ; Set queued cmd
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 3B: Handle single-target spell
C32AAE:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BNE C32AC6      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$03        ; Using left/right?
         BEQ C32AF3      ; Branch if not
C32AC6:  JSR C30EA3      ; Sound: Cursor
         JSR C32D13      ; Spell
         JSR C350F5      ; Compute index
         LDA $C46AC0,X   ; Spell properties
         AND #$20        ; Can multi-target?
         BEQ C32AF3      ; Branch if not
         LDA $4E         ; Cursor row
         STA $5F         ; Save for revert
         LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         LDA #$3D        ; C3/2D78
         STA $26         ; Next: Target all
         JMP C3089F      ; Create blinkers

; Fork: Handle A
C32AF3:  LDA $08         ; Pushing A?
         BMI C32B0C      ; Branch if so

; Fork: Handle B
C32AFC:  LDA $09         ; Pushing B?
         BPL C32B0B      ; Exit if not
         LDA #$3C        ; C3/2D1C
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor
C32B0B:  RTS

; Fork: Handle spell usage on single target
C32B0C:  STZ $9C         ; Halve HP gain: N
         JSR C32CCC      ; Get LV, Mag.Pwr
         JSR C32D0B      ; Target's address
         JSR C32C14      ; Valid target?
         BCC C32B32      ; Fail if not
         JSR C32CEA      ; Lower caster's MP
         JSR C30EE5      ; Play heal sound
         JSR C32D0B      ; Target's address
         TYX             ; Move it to X
         LDA $14,X       ; Status LB
         STA $F8         ; Set as target's
         LDA $15,X       ; Status HB
         STA $FB         ; Set as target's
         JSR C32B39      ; Adjust HP, status
         BRA C32BDE      ; Redo GFX, test MP

; Fork: Invalid target
C32B32:  JMP C3B66F      ; Buzzer + Mosaic

; Adjust spell target's HP and status
C32B39:  LDX $0B,Y       ; Max HP
         STX $11B2       ; Set target's
         PHY             ; Save index
         JSR C32D13      ; Spell number
         LDX $00         ; Mode: Magic
         JSL $C20009     ; Get gain/status
         PLY             ; Actor's address
         LDA $9C         ; One target?
         REP #$21        ; 16-bit A; C-
         BEQ C32B5C      ; Branch if so
         LSR $11B0       ; Halve HP gain
C32B5C:  LDA $11B0       ; HP gain
         ADC $0009,Y     ; Add actor HP
         STA $0009,Y     ; Set actor HP
         JSR C32B9A      ; Enforce max
         LDA $FC         ; Status LB
         STA $0014,Y     ; Set actor's
         LDA $FF         ; Status HB
         STA $0015,Y     ; Set actor's
         LDA $9C         ; One target?
         BNE C32BB9      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $69,X       ; Actor's address
         JSL $C20006     ; Get gear data
         JSR C32D0B      ; Actor's address
         STY $67         ; Memorize it
         LDA $11D2       ; Immunities
         JSR C391EC      ; Deny ailments
         LDA $11D4       ; Auto status
         JMP C391FB      ; Handle Float

; Keep HP from exceeding max HP, clear Carry if lower
C32B9A:  LDX $0B,Y       ; Max HP
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         LDX $09,Y       ; Current HP
         CPX $F3         ; Under max?
         BCC C32BB9      ; Exit if so
         LDX $F3         ; Max HP
         STX $09,Y       ; Set HP
;        SEC             ; ...
C32BB9:  RTS

; Keep MP from exceeding max MP, clear Carry if lower
C32BBC:  LDX $0F,Y       ; Max MP
         JSR C30D65      ; Add gear bonus
         JSR C30D9F      ; Cap at 999
         LDX $0D,Y       ; Current MP
         CPX $F3         ; Under max?
         BCC C32BDB      ; Exit if so
         LDX $F3         ; Max MP
         STX $0D,Y       ; Set MP
;        SEC             ; ...
C32BDB:  RTS

; Redraw party after spell usage, exit menu if short on MP
C32BDE:  JSR C32C01      ; Redraw party
         JSR C32CDF      ; Check caster gear
         JSR C32D03      ; Caster's address
         JSR C32D13      ; Spell used
         JSR C3510D      ; Define cost
         STX $E7         ; Memorize it
         LDX $0D,Y       ; Caster's MP
         CPX $E7         ; Can recast?
         BCS C32C00      ; Exit if so
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDA #$3C        ; C3/2D1C
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
C32C00:  RTS

; Redraw party after spell or item usage
C32C01:  LDA $4B         ; Cursor slot, 0 if MT
         STA $9C         ; Set portrait slot
         JSR C324EE      ; Clear icons/portraits
         JSR C36A15      ; Clear names, stats
         JSR C33193      ; Redo stats/icons/faces
         JSR C36C09      ; Load portrait colors
         JMP C36EBF      ; Queue portrait upload

; Establish whether spell target is valid
C32C14:  LDA $0014,Y     ; Wound status?
         BMI C32C40      ; Branch if so
         JSR C32D13      ; Spell
         CMP #$2D        ; Cure?
         BEQ C32C76      ; Branch if so
         CMP #$2E        ; Cure 2?
         BEQ C32C76      ; Branch if so
         CMP #$2F        ; Cure 3?
         BEQ C32C76      ; Branch if so
         CMP #$32        ; Antdot?
         BEQ C32C6D      ; Branch if so
         CMP #$33        ; Remedy?
         BEQ C32C64      ; Branch if so
         CMP #$22        ; Float?
         BEQ C32C4D      ; Branch if so
         CMP #$23        ; Imp?
         BEQ C32C84      ; Succeed if so
         CMP #$2C        ; Dispel?
         BEQ C32C56      ; Branch if so
         BRA C32C82      ; Make spell fail

; Fork: Wound
C32C40:  JSR C32D13      ; Spell
         CMP #$30        ; Life?
         BEQ C32C84      ; Succeed if so
         CMP #$31        ; Life 2?
         BEQ C32C84      ; Succeed if so
         BRA C32C82      ; Make spell fail

; Fork: Float
C32C4D:  LDA $0015,Y     ; Float status?
         BMI C32C82      ; Fail if so
         BRA C32C84      ; Make spell work

; Fork: Dispel
C32C56:  LDA $0014,Y     ; Status LB
         AND #$7F        ; Ignore Wound...
         ORA $0015,Y     ; Add high byte
         AND #$90        ; Clear or Float?
         BEQ C32C82      ; Fail if neither
         BRA C32C84      ; Make spell work

; Fork: Remedy
C32C64:  LDA $0014,Y     ; Dark? Poison?
         AND #$45        ; Or Petrify?
         BEQ C32C82      ; Fail if none
         BRA C32C84      ; Make spell work

; Fork: Antdot
C32C6D:  LDA $0014,Y     ; Status
         AND #$04        ; Poison?
         BEQ C32C82      ; Fail if not
C32C84:  SEC             ; Make spell work
         RTS

; Fork: Cure spells
C32C76:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C32C82      ; Fail if any
         JSR C32B9A      ; At full HP?
         BCC C32C84      ; Succeed if not
C32C82:  CLC             ; Make spell fail
         RTS

; Handle spell usage on party
C32C86:  STZ $AF         ; Valid target: N
         LDA #$01        ; Half gain, etc.
         STA $9C         ; Set heal mode
         JSR C32CCC      ; Get LV, Mag.Pwr
         TDC             ; Member: 1st
C32C90:  PHA             ; Save member
         JSR C32D0_      ; Actor's address
         BEQ C32CB8      ; Skip if nobody
         JSR C32C14      ; Valid target?
         BCC C32CB8      ; Skip if not
         LDA $0014,Y     ; Status LB
         STA $F8         ; Set target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set target's
         JSR C32B39      ; Adjust HP, status
         JSR C32CCC      ; Get LV, Mag.Pwr
         LDA $AF         ; 1st valid target?
         BNE C32CB8      ; Branch if not
         JSR C30EE5      ; Play heal sound
         JSR C32CEA      ; Lower caster's MP
         INC $AF         ; Valid target: Y
C32CB8:  TDC             ; Clear A
         PLA             ; Member slot
         INC A           ; Member slot +1
         CMP #$04        ; Done all 4?
         BNE C32C90      ; Loop if not
         LDA $AF         ; Is any valid?
         BNE C32CC9      ; Branch if so
         JSR C3B66F      ; Buzzer + Mosaic
C32CC9:  JMP C32BDE      ; Redo GFX, test MP

; Load caster's Mag.Pwr and level (for C2/0009)
C32CCC:  JSR C32CDF      ; Define stats
         LDA $11A0       ; Mag.Pwr
         STA $11AE       ; Memorize it
         JSR C32D03      ; Actor's address
         LDA $0008,Y     ; Level
         STA $11AF       ; Memorize it
         RTS

; Load member's stats and properties with gear
C32CDF:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor
         JSL $C20006     ; Load data
         RTS

; Decrease caster's MP
C32CEA:  JSR C32D13      ; Spell
         JSR C3510D      ; Define cost
         STX $E7         ; Memorize it
         JSR C32D03      ; Define Y
         REP #$20        ; 16-bit A
         LDA $000D,Y     ; Actor's MP
         SEC             ; Prepare SBC
         SBC $E7         ; Subtract cost
         STA $000D,Y     ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Get caster's SRAM block address
C32D03:  TDC             ; Clear A
         LDA $28         ; Member slot
         BRA C32D0_      ; Branch below

; Get target's SRAM block address
C32D0B:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
C32D0_:  ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; SRAM address
         RTS

; Get selected spell
C32D13:  TDC             ; Clear A
         LDA $99         ; Spell slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell
         RTS

; 3C: Return to Magic menu
C32D1C:  JSR C3352F      ; Reset/Stop stuff
         JSR C36A08      ; Set Win1 bounds
         LDA #$42        ; Allow back row
         TRB $45         ; And cursor memory
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C34DBC      ; Set to shift text
         JSR C34C80      ; Draw menu, etc.
         JSR C307B0      ; Queue cursor OAM
         JSR C32130      ; Create scrollbar
         JSR C34B82      ; Load navig data
         JSR oldcur      ; Restore cursor pos
         JSR C34B8B      ; Relocate cursor
         JSR C32158      ; Draw spells, etc.
         JSR C30E6E      ; Upload BG3 A+B
         JSR C31368      ; Refresh screen
         LDY $00         ; X: 0
         STY $35         ; Set BG1 X-Pos
         JSR C31B99      ; Queue desc anim
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30EFD      ; Queue lists upload
         LDA #$1A        ; C3/27E2
         STA $27         ; Queue Magic menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 3D: Handle multitarget spell
C32D78:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BNE C32D90      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$03        ; Using left/right?
         BEQ C32D9B      ; Branch if not
C32D90:  JSR C32DB7      ; Swap cursors
         LDA #$3B        ; C3/2AAE
         STA $26         ; Next: One target
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle A
C32D9B:  LDA $08         ; Pushing A?
         BPL C32DA4      ; Branch if not
         JMP C32C86      ; Handle spell

; Fork: Handle B
C32DA4:  LDA $09         ; Pushing B?
         BPL C32DD0      ; Exit if not
         JSR C32DB7      ; Swap cursors
         LDA #$3C        ; C3/2D1C
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Revert to a single target for spell
C32DB7:  JSR C32F98      ; Preload nav data
         JSR C307B0      ; Queue cursor OAM
         LDY #C32FC0     ; C3/2FC0
         JSR qanim0      ; Queue D-Pad fn
         JSR C311B0      ; Run anim queue
         LDA $5F         ; Old cursor row
         STA $4E         ; Set as current
         LDA #$08        ; Blinkers: Off
         TRB $46         ; Set menu flag
C32DD0:  RTS

; Swap actor info for switched members
C32DD1:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA $4B         ; Chosen slot B
         TAY             ; Index it
         LDA $75,X       ; A's party info
         PHA             ; Memorize it
         LDA $0075,Y     ; B's party info
         STA $75,X       ; Set as A's
         PLA             ; A's party info
         STA $0075,Y     ; Set as B's
         LDA $69,X       ; A's actor ID
         PHA             ; Memorize it
         LDA $0069,Y     ; B's actor ID
         STA $69,X       ; Set as A's
         PLA             ; A's actor ID
         STA $0069,Y     ; Set as B's
         TDC             ; Clear A
         TXA             ; Chosen slot A
         ASL A           ; Double it
         TAX             ; Index it
         TYA             ; Chosen slot B
         ASL A           ; Double it
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA $6D,X       ; A's data adr
         PHA             ; Memorize it
         LDA $006D,Y     ; B's data adr
         STA $6D,X       ; Set as A's
         PLX             ; A's data adr
         STX $6D,Y       ; Set as B's
         SEP #$20        ; 8-bit A
         RTS

; Toggle member's row, set to shift portrait
C32E10:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $75,X       ; Party info
         STA $E0         ; Memorize it
         LDA $60,X       ; Queue index
         TAX             ; Index it
         LDA #$20        ; Row bit
         BIT $E0         ; Front row?
         BEQ C32E29      ; Branch if so
         TRB $E0         ; Row: Front
         LDA #$03        ; Shift: Right
         BRA C32E2F      ; Skip 2 lines
C32E29:  TSB $E0         ; Row: Back
         LDA #$02        ; Shift: Left
C32E2F:  STA $7E3649,X   ; Set anim mode
;        TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $E0         ; Party info
         STA $75,X       ; Set member's
         RTS

; Set to delete all portraits
C32E3C:  TDC             ; Clear A
         LDX #$0003      ; 1st: Member 4
.loop    PHX             ; Save member
         LDA $60,X       ; Queue index
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Portrait: Off
         PLX             ; Member slot
         DEX             ; Member slot -1
         BPL .loop       ; Loop till < 0
         RTS

; Jump table for main menu
C32E6C:  dw C32E86       ; Item
         dw C32E90       ; Skills
         dw C32E90       ; Equip
         dw C32E90       ; Relic
         dw C32E90       ; Status
         dw C32E7A       ; Config
         dw C32EAA       ; Save

; Invoke Config menu
C32E7A:  STZ $5F         ; Cursor: Bat.Mode
         STZ $26         ; Next: Fade-out
         LDA #$0D        ; C3/1C7D
         STA $27         ; Queue Config
         JMP C30EB2      ; Sound: Click

; Invoke Item menu
C32E86:  STZ $26         ; Next: Fade-out
         LDA #$07        ; C3/1AD6
         STA $27         ; Queue Item menu
         JMP C30EB2      ; Sound: Click

; Initialize portrait targeting with main menu command
C32E90:  LDA #$02        ; List cursor: Off
         TRB $46         ; Set menu flag
         JSR C32F98      ; Preload nav data
         LDY #C32FC0     ; C3/2FC0
         JSR qanim0      ; Queue D-Pad fn
         JSR C32F06      ; Create blinker
         LDA #$06        ; C3/1DE8
         STA $26         ; Next: Targeting
         JMP C30EB2      ; Sound: Click

; Invoke Save menu if allowed
C32EAA:  LDA $0201       ; Can save here?
         BPL C32EBF      ; Fail if not
         STZ $26         ; Next: Fade-out
         LDA #$13        ; C3/1CA0
         STA $27         ; Queue Save menu
         JMP C30EB2      ; Sound: Click
C32EBF:  JMP C3B66F      ; Buzzer + Mosaic

; Initiate shifting to Order menu
C32EC6:  LDA #$02        ; List cursor: Off
         TRB $46         ; Set menu flag
         JSR C32F98      ; Preload nav data
         LDY #C32FC0     ; C3/2FC0
         JSR qanim0      ; Queue D-Pad fn
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off
         TRB $46         ; Order cursor: Off
         LDA #$0F        ; C3/240C
         STA $27         ; Queue: Choice 1
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         RTS

; Create blinking cursor for Espers menu
C32EEB:  LDY #C308D1     ; C3/08D1
         JSR qanim2      ; Queue OAM fn
         PEA $3638       ; Pos: 56, 54
         JMP C3E9DY      ; Set sprite's

; Create blinking cursor to the right of main cursor
C32F06:  LDY #C307FF     ; C3/07FF
         JSR qanim2      ; Queue OAM fn
         LDA $55         ; Cursor's X
         INC A           ; +1 px right
         INC A           ; +1 px right
         STA $7E33CA,X   ; Set blinker X
         LDA $56         ; Cursor's Y
         BRA C32F2_      ; Set blinker Y

; Create blinking cursor to northeast of main cursor
C32F21:  LDY #C307FF     ; C3/07FF
         JSR qanim1      ; Queue OAM fn
         LDA $55         ; Cursor's X
         CLC             ; Prepare ADC
         ADC #$04        ; +4 px right
         STA $7E33CA,X   ; Set blinker X
         LDA $56         ; Cursor's Y
         SEC             ; Prepare SBC
         SBC #$04        ; +4 px up
C32F2_:  STA $7E344A,X   ; Set blinker Y
         RTS

; Update cursor position in main menu list
C32F42:  BNE C32F6B      ; If mode 1

; Mode 0: Initialize data
C32F4A:  LDA #$02        ; Show cursor: Y
         TSB $46         ; Set menu flag
         INC $3649,X     ; Mode +1
         LDY #C32F85     ; C3/2F85
         JSR C305FE      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C32F65      ; Branch if not
         LDY $022B       ; Former position
         STY $4D         ; Set as current
C32F65:  LDY #C32F8A     ; C3/2F8A
         JSR C30640      ; Set cursor X/Y

; Mode 1: Update position
C32F6B:  LDA $46         ; Menu flags
         BIT #$02        ; Delete cursor?
         BEQ C32F83      ; Dequeue if so
         JSR C3072D      ; Handle D-Pad
         LDY #C32F8A     ; C3/2F8A
         JSR C30640      ; Set cursor X/Y
         LDY $4D         ; Cursor position
         STY $022B       ; To cursor memory
         SEC             ; Set to requeue
         RTS             ; Exit
C32F83:  CLC             ; Set to dequeue
         RTS

; Preload nav data for portrait selection, disable empty slots
C32F98:  JSR C32FB1      ; Load navig data
         TDC             ; Clear A
         TAX             ; 1st: Member 1
C32F9E:  LDA $69,X       ; Actor in slot
         BPL C32FAA      ; Skip if any
         PHX             ; Save slot
         TXA             ; Move it to A
         ASL A           ; Double it
         TAX             ; Reindex it
         STZ $85,X       ; Disable slot
         PLX             ; Member slot
C32FAA:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C32F9E      ; Loop if not
         RTS

; Preload navigation data for portrait selection
C32FB1:  LDX #$000C      ; Base index
C32FB3:  LDA.L C33042,X  ; Navig data
         STA $80,X       ; Save in RAM
         DEX             ; Index -1
         BPL C32FB3      ; Loop till < 0
         RTS

; Update movable cursor's position for portrait selection
C32FC0:  BNE C33014      ; If mode 1

; Mode 0: Initialize data
C32FC8:  LDA #$14        ; Main cursor: On
         TSB $46         ; Enable D-Pad
         INC $3649,X     ; Mode +1
         JSR C32FF5      ; Load navig data
         LDA $45         ; Menu flags
         ASL A           ; Skip cursor mem?
         BMI C32FE6      ; Branch if so
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C32FE6      ; Branch if not
         LDY $022D       ; Former position
         STY $4D         ; Set as current
C32FE6:  JSR C33008      ; Relocate cursor
         LDA $55         ; On empty slot?
         BNE C32FF3      ; Exit if not
         JSR C32FF5      ; Target leader
         JSR C33008      ; Relocate cursor
C32FF3:  SEC             ; Set to requeue
         RTS

; Load custom nav data for portrait selection, target leader
C32FF5:  LDY #$0080      ; 00/0080
         TDC             ; Src HB: 00
         JSR C30600      ; Load navig data
         JMP C3061E      ; Target leader

; Set portrait cursor's slot and base pixel position
C33008:  LDY #$0085      ; 00/0085
         STY $E7         ; Set src LBs
         STZ $E9         ; Src HB: 00
         JMP C30643      ; Relocate cursor

; Mode 1: Update position
C33014:  LDA $45         ; Menu flags
         ASL A           ; Skip cursor mem?
         BMI C3301F      ; Branch if so
         LDY $4D         ; Cursor position
         STY $022D       ; To cursor memory
C3301F:  LDA $46         ; Menu flags
         BIT #$04        ; Delete cursor?
         BEQ C33040      ; Dequeue if so
         BIT #$10        ; Swapping chars?
         BEQ C3303E      ; Exit if so
C3302B:  JSR C3072D      ; Handle D-Pad
         JSR C33008      ; Relocate cursor
         LDA $55         ; On empty slot?
         BEQ C3302B      ; Retarget if so
C3303E:  SEC             ; Set to requeue
         RTS             ; Exit
C33040:  CLC             ; Set to dequeue
         RTS

; Queue menu fade-out
C3304F:  LDY #C3309F     ; C3/309F
         JMP qanim0      ; Put in queue

; Queue menu fade-in
C33056:  LDY #C330CA     ; C3/30CA
         JMP qanim0      ; Put in queue

; Queue mosaic effect
C3305D:  LDY #C33064     ; C3/3064
         JMP qanim0      ; Put in queue

; Process queued mosaic effect
C33064:  BNE C33079      ; If mode 1

; Mode 0: Initialize mosaic
C3306C:  INC $3649,X     ; Mode +1
         STZ $33CA,X     ; 1st: C3/3097
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set timer

; Mode 1: Sustain mosaic
C33079:  LDA $3349,X     ; Timer expired?
         BEQ C33095      ; Dequeue if so
         DEC $3349,X     ; Timer -1
;        TDC             ; Clear A
         LDA $33CA,X     ; Table index
         INC $33CA,X     ; Table index +1
         TAX             ; Index original
         LDA.L C33097,X  ; Parameters
         STA $B5         ; Save in RAM
         SEC             ; Set to requeue
         RTS             ; Exit
C33095:  CLC             ; Set to dequeue
         RTS

; Mosaic parameters
C33097:  db $17          ; Intensity 1 for BG1-BG3
C33098:  db $27          ; Intensity 2 for BG1-BG3
C33099:  db $37          ; Intensity 3 for BG1-BG3
C3309A:  db $47          ; Intensity 4 for BG1-BG3
C3309B:  db $37          ; Intensity 3 for BG1-BG3
C3309C:  db $27          ; Intensity 2 for BG1-BG3
C3309D:  db $17          ; Intensity 1 for BG1-BG3
C3309E:  db $07          ; Intensity 0 for BG1-BG3

; Process queued menu fade-out
C3309F:  BNE C330B1      ; If mode 1

; Mode 0: Initialize brightness
C330A7:  INC $3649,X     ; Mode +1
         LDA #$0F        ; BRT: 15 and ON
         STA $33CA,X     ; Set next BRT

; Mode 1: Decrease brightness
C330B1:  LDY $20         ; Timer expired?
         BEQ C330C4      ; Finalize if so
         LDA $33CA,X     ; Next brightness
         STA $44         ; Set as current
         DEC A           ; Next BRT -1
         DEC A           ; Next BRT -1
         STA $33CA,X     ; Save changes
         SEC             ; Set to requeue
         RTS             ; Exit
C330C4:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Process queued menu fade-in
C330CA:  BNE C330DC      ; If mode 1

; Mode 0: Initialize brightness
C330D2:  INC $3649,X     ; Mode +1
         LDA #$01        ; BRT: 1 and ON
         STA $344A,X     ; Set next BRT

; Mode 1: Increase brightness
C330DC:  LDY $20         ; Timer expired?
         BEQ C330EF      ; Finalize if so
         LDA $344A,X     ; Next brightness
         STA $44         ; Set as current
         INC A           ; Next BRT +1
         INC A           ; Next BRT +1
         STA $344A,X     ; Save changes
         SEC             ; Set to requeue
         RTS             ; Exit
C330EF:  LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Draw and upload main menu
C330F5:  JSR C33F99      ; Apply user font
         JSR bg2b_cl     ; Clear BG2 A+B
         JSR C36A19      ; Clear BG1 map B
         JSR C36A41      ; Clear BG3 map B
         LDX #C331BB     ; C3/31BB
         JSR boxes       ; Draw most boxes
         JSR C33170      ; Draw stats, etc.
         JSR C3326C      ; Draw time
         JSR C331F3      ; Draw menu list
         JMP up_txt      ; Upload text maps

; Draw and upload save confirmation menu
C33128:  PEA C33765      ; Text ptrs loc
         LDA #$05        ; Msg strings: 5
         BRA C3314_      ; Skip 2 lines

; Draw and upload load confirmation menu
C3314C:  PEA C3375D      ; Text ptrs loc
         LDA #$04        ; Msg strings: 4
C3314_:  PHA             ; Memorize it
         JSR C33F99      ; Apply user font
         JSR C36E82      ; Load portraits
         JSR C36C09      ; And their colors
         JSR C331A8      ; Upload skin
         LDX #C331C7     ; C3/31C7
         JSR C30341      ; Draw main window
         LDX #C331CB     ; C3/31CB
         JSR C30341      ; Draw Yes/No box
         JSR C33170      ; Draw stats, etc.
         JSR C33295      ; Draw time
         JSR C3C2F2      ; Color: User's
         PLA             ; String count
         PLX             ; Text ptrs loc
         JSR C369BA      ; Draw question
         JMP up_txt      ; Upload text maps

; Draw elements shared by main menu and save file submenus
C33170:  TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         LDX #C331BF     ; C3/31BF
         JSR boxes       ; Draw small boxes
         JSR C30E52      ; Upload windows
         JSR C3318A      ; Draw party info
         BRA C33221      ; Draw game stats

; Draw party info
C3318A:  JSR C36A15      ; Clear BG1 map A
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A46      ; Clear BG3 map C
C33193:  JSR C332F1      ; Handle member 1
         JSR C3333D      ; Handle member 2
         JSR C33389      ; Handle member 3
         JMP C333D5      ; Handle member 4

; Upload skin for viewed save file
C331A8:  TDC             ; Clear A
         LDA $66         ; File viewed
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C331A_-2,X); Upload skin

; Jump table for the above
C331A_:  dw C33AA1       ; Handle file 1
         dw C33ABD       ; Handle file 2
         dw C33AD9       ; Handle file 3

; Draw list of submenus in main menu
C331F3:  JSR C3C2F2      ; Color: User's
         LDX #C33729     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C369BA      ; Do Item..Config
         LDA $0201       ; Can save here?
         BPL C33216      ; Branch if not
         LDA #$20        ; Color: User's
         BRA C33218      ; Skip a line
C33216:  LDA #$24        ; Color: Gray
C33218:  STA $29         ; Set palette
         LDY #C337FD     ; Text pointer
         JMP C302F9      ; Draw "Save"

; Draw most text in small windows of main menu or save file submenu
C33221:  JSR C3C2F2      ; Color: User's
         LDY #C3380B     ; Text pointer
         JSR C302F9      ; Draw ":"
         JSR C3C2F7      ; Color: Blue
         LDX #C33723     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw SE titles
         LDY #C33817     ; Text pointer
         JSR C302F9      ; Draw "Gp"
         JSR C332CE      ; Cap GP
         JSR C3C2F2      ; Color: User's
         LDY $1866       ; Steps LBs
         STY $F1         ; Memorize them
         LDA $1868       ; Steps HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         LDX #$7DF7      ; Text position
         JSR C304AC      ; Draw step count
         PEA $7EB7       ; Text position
gp_pty:  LDY $1860       ; Gold LBs
         STY $F1         ; Memorize them
         LDA $1862       ; Gold HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         PLX             ; Text position
         JMP C304AC      ; Draw GP total

; Draw time in main menu
C3326C:  LDA $1188       ; Timer 0 flags
         BIT #$10        ; Override clock?
         BEQ C33289      ; Branch if not
         LDY $1189       ; Countdown timer
         JSR C332B2      ; Divide by 60
         JSR C332B2      ; Divide by 60
         LDA $E7         ; Minutes
         STA $1863       ; Set shown hours
         LDA $4216       ; Seconds
         STA $1864       ; Set shown mins
         BRA C33295      ; Draw time

; Fork: Normal clock
C33289:  LDY $021B       ; Hours, mins
         STY $1863       ; Save in SRAM
         LDA $021D       ; Seconds
         STA $1865       ; Save in SRAM

; Fork: Draw time
C33295:  JSR C3C2F2      ; Color: User's
         LDA $1863       ; Shown hours
         JSR C304E0      ; Turn into text
         LDX #$7CFB      ; Text position
         JSR C304B6      ; Draw 2 digits
         LDA $1864       ; Shown minutes
         JSR C304F9      ; Turn into text
         LDX #$7D01      ; Text position
         JMP C304B6      ; Draw 2 digits

; Divide countdown timer's value by 60
C332B2:  STY $4204       ; Set dividend
         LDA #$3C        ; 60
         STA $4206       ; Set divisor
         JSR x16         ; Waste 20 cycles
         LDY $4214       ; Quotient
         STY $E7         ; Memorize it
         RTS

; Enforce GP cap
C332CE:  LDY #$967F      ; Cap LBs
         CPY $1860       ; C- if < GP LBs
         LDA #$98        ; Cap HB
         SBC $1862       ; Deduct GP w/ C
         BCS C332EA      ; Exit if < 10M
         STY $1860       ; Set gold LBs
         LDA #$98        ; Cap HB
         STA $1862       ; Set gold HB
C332EA:  RTS

; Hi-fork: Hide portrait
C332EB:  JSR C30A22      ; Init portrait
         JMP C3341B      ; Hide portrait

; Draw info for member 1
C332F1:  LDA $69         ; Nobody here?
         BMI C332EB      ; Abort if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         JSR C35F34      ; Color: Blue
         LDX #C33741     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3927      ; Class/KO pos
         LDX #$1578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C33731     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C369BA      ; Draw both "/"
         LDY #$3919      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C3332D     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30A22      ; Create portrait

; Hi-fork: Hide portrait
C33337:  JSR C30A4B      ; Init portrait
         JMP C3341B      ; Hide portrait

; Draw info for member 2
C3333D:  LDA $6A         ; Nobody here?
         BMI C33337      ; Abort if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         JSR C35F34      ; Color: Blue
         LDX #C33747     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3AA7      ; Class/KO pos
         LDX #$4578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C33735     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C369BA      ; Draw both "/"
         LDY #$3A99      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C33379     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30A4B      ; Create portrait

; Hi-fork: Hide portrait
C33383:  JSR C30A76      ; Init portrait
         BRA C3341B      ; Hide portrait

; Draw info for member 3
C33389:  LDA $6B         ; Nobody here?
         BMI C33383      ; Abort if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         JSR C35F34      ; Color: Blue
         LDX #C3374D     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3C27      ; Class/KO pos
         LDX #$7578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C33739     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C369BA      ; Draw both "/"
         LDY #$3C19      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C333C5     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30A76      ; Create portrait

; Draw info for member 4
C333D5:  LDA $6C         ; Nobody here?
         BMI C333CF      ; Abort if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         JSR C35F34      ; Color: Blue
         LDX #C33753     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3DA7      ; Class/KO pos
         LDX #$A578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C3373D     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C369BA      ; Draw both "/"
         LDY #$3D99      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C33411     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30AA1      ; Create portrait

; Fork: Hide portrait
C333CF:  JSR C30AA1      ; Init portrait
;        BRA C3341B      ; Hide portrait

; Hide portrait for vacant member slot
C3341B:  LDA #$D8        ; Base Y: 216
         STA $7E344A,X   ; Set sprite's
         RTS

; Display actor's status (excludes Status menu)
C33427:  STX $E7         ; Save icon pos
         JSR C33519      ; Set text pos
         LDA $0014,Y     ; Wounded?
         BMI C334B0      ; Draw it if so
         AND #$70        ; Clear/Imp/Pet
         STA $E1         ; Memorize them
         LDA $0014,Y     ; Status LB
         AND #$07        ; Dark/Zom/Poison
         ASL A           ; Put in bits 1-3
         STA $E2         ; Memorize them
         LDA $0015,Y     ; Status HB
         AND #$80        ; Isolate Float
         ORA $E1         ; Add Clear, etc.
         ORA $E2         ; Add Dark, etc.
         BEQ C334A9      ; Exit if none
icons:   STZ $F1         ; Sprite index LB
         STZ $F2         ; Sprite index HB
         LDX #$0007      ; Status left: 7
C33451:  PHX             ; Save counter
         ASL A           ; Got current?
         BCC C3349C      ; Skip if not
         PHA             ; Save status
         LDY #C37B42     ; C3/7B42
         JSR qanim3      ; Queue icon OAM
         JSR C3EA6C      ; Follow BG1: Y
         LDA $48         ; Anim mode
         STA $7E3649,X   ; Set icon's
         PHX             ; Save queue index
         LDX $F1         ; Sprite index
         REP #$20        ; 16-bit A
         LDA $D8EC25,X   ; Anim ptr LBs
         TAY             ; Put in Y
         PLX             ; Queue index
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Anim ptr HB
         JSR anm_st      ; Set icon's ptr
         LDY $E7         ; Position
         JSR objpos      ; Set icon's
         LDA #$0A        ; Modifier: 10
         CLC             ; Prepare ADC
         ADC $E7         ; Add current X
         STA $E7         ; Set current X
         PLA             ; Statuses
C3349C:  INC $F1         ; Sprite index +1
         INC $F1         ; Sprite index +1
         PLX             ; Statuses left
         DEX             ; One less left
         BNE C33451      ; Loop till last
         JMP C3C2F2      ; Color: User's
                         ; ^ For stats
; Fork: Draw actor class (SFC)
C334A9:  JSR C3C2F2      ; Color: User's
         BRA C334E5      ; RTS...

; Fork: Draw "Wounded"
C334B0:  LDX $00         ; Index: 0
C334B8:  LDA.L C3371B,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$0008      ; Copied 8?
         BNE C334B8      ; Loop if not
         JSR C3808A      ; Color: Gray
         JMP C37FD_      ; Draw string

; Draw actor name
C334CF:  JSR C33519      ; Set pos/WRAM/Y
C334D2:  LDX #$0006      ; Letters: 6
C334D5:  LDA $0002,Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE C334D5      ; Loop till last
         JMP C37FD_      ; Draw string

; Draw actor class (SFC)
C334E5:  RTS

; Draw equipped esper
C334E6:  JSR C33519      ; Set pos/WRAM/Y
         LDA $001E,Y     ; Actor's esper
         CMP #$FF        ; None?
         BEQ C33508      ; Blank if so
drw_esp: XBA             ; Put in B
         LDX.W #!esp_ns  ; Letters: 8
         LDA.B #!esp_np!h; Text ptr HB
         LDY.W #!esp_np  ; Text ptr LBs
         JSR fw_txt      ; Load name
         JMP C37FD_      ; Draw string

; Fork: Blank esper name
C33508:  LDY.W #!esp_ns  ; Spaces: 8
         JMP spacedr     ; Draw 8 spaces

; Prepare name drawing
C33519:  JSR wm9E8B      ; WRAM: 7E/9E8B
         REP #$20        ; 16-bit A
         TYA             ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDY $67         ; Actor address
         RTS

; Reset OAM and anim queue; disable screen, interrupts, pad, HDMA
C3352F:  JSR C31114      ; Reset OAM, queue
         JMP C3C576      ; Disable pad, etc

; Prepare fade-in
C33541:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         JMP C31368      ; Refresh screen

; Redraw time in main menu
C33548:  JSR C30F39      ; Queue BG3 upload
         JMP C3326C      ; Draw time

; Queue main screen designation HDMA for main menu
C3354E:  LDX #$00DE      ; Base index
         LDA #$17        ; BG1-3, sprites
C33552:  STA $7E9A09,X   ; Set MS desig.
         DEX             ; Index -1
         BPL C33552      ; Loop till < 0
         LDA #$40        ; 1Rx1B via ptrs
         STA $4360       ; Set DMA mode
         LDA #$2C        ; $212C
         STA $4361       ; To MS desig.
         LDY #C3357B     ; C3/357B
         STY $4362       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4364       ; Set src HB
         LDA #$7E        ; Bank: 7E
         STA $4367       ; Set indir HB
         LDA #$40        ; Channel: 6
         TSB $43         ; Queue HDMA-6
         RTS

; Main screen designation table for main menu
C3357B:  db $F0,$09,$9A  ; 112 lines, use $9A09
         db $F0,$79,$9A  ; 112 lines, use $9A79
         db $00          ; End

; Queue member swap animation for Order menu
C33582:  LDA $28         ; First choice
         CMP $4B         ; Above second?
         BCC C3359D      ; Branch if so
         LDY #C335D4     ; C3/35D4
         JSR qanim3      ; Queue B's anim
         JSR C335C1      ; Set slot B's Y
         LDY #C3361F     ; C3/361F
         JSR qanim3      ; Queue A's anim
         BRA C335B2      ; Set slot A's Y

; Fork: First choice is above second
C3359D:  LDY #C335D4     ; C3/35D4
         JSR qanim3      ; Queue A's anim
         JSR C335B2      ; Set slot A's Y
         LDY #C3361F     ; C3/361F
         JSR qanim3      ; Queue B's anim
         BRA C335C1      ; Set slot B's Y

; Fork: Set base scanline for slot A
C335B2:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         BRA C335C_      ; Skip 2 lines

; Fork: Set base scanline for slot B
C335C1:  TDC             ; Clear A
         LDA $4B         ; Chosen slot B
C335C_:  TXY             ; Queue index
         TAX             ; Index slot
         LDA.L C335D0,X  ; Base scanline
         TYX             ; Queue index
         STA $7E33CA,X   ; Put in queue
         RTS

; Base scanlines for member swap animation
C335D0:  db $0D          ; Member slot 1
         db $3D          ; Member slot 2
         db $6D          ; Member slot 3
         db $9D          ; Member slot 4

; Erase member slot contents from the top down, and vice versa
C335D4:  BNE C33602      ; If mode 1

; Mode 0: Erase 4 lines
C335E3:  LDA $22         ; Time left
         CMP #$0C        ; 12 frames?
         BEQ C335FA      ; Unmask if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$06        ; On MS: BG2+BG3
         JSR C33677      ; Hide 4 lines
         STA $33CA,X     ; Save scanline
         SEC             ; Set to requeue
         RTS

; Fork: Start unmasking
C335FA:  INC $3649,X     ; Mode +1
         DEC $33CA,X     ; Scanline -1

; Mode 1: Print 4 lines
C33602:  LDA $45         ; Menu flags
         BIT #$08        ; Got go-signal?
         BEQ C3361B      ; Exit if not
         LDA $22         ; Timer expired?
         BEQ C3361D      ; Dequeue if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$17        ; On MS: BGs+OBJ
         JSR C3368D      ; Unhide 4 lines
         STA $33CA,X     ; Save scanline
C3361B:  SEC             ; Set to requeue
         RTS             ; Exit
C3361D:  CLC             ; Set to dequeue
         RTS

; Erase member slot contents from the bottom up, and vice versa
C3361F:  CMP #$02        ; Mode 1?
         BEQ C33637      ; Branch if so
         BCS C33658      ; If mode 2

; Mode 0: Start from bottom
C33629:  INC $3649,X     ; Mode +1
         LDA $33CA,X     ; Top scanline
         CLC             ; Prepare ADC
         ADC #$2F        ; Go 47 px down
         STA $33CA,X     ; Save changes

; Mode 1: Erase 4 lines
C33637:  LDA $22         ; Time left
         CMP #$0C        ; 12 frames?
         BEQ C33650      ; Unmask if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$06        ; On MS: BG2+BG3
         JSR C3368D      ; Hide 4 lines
         STA $33CA,X     ; Save scanline
         DEC $22         ; Anim timer -1
         SEC             ; Set to requeue
         RTS

; Fork: Start ummasking
C33650:  INC $3649,X     ; Mode +1
         INC $33CA,X     ; Scanline +1

; Mode 2: Print 4 lines
C33658:  LDA $45         ; Menu flags
         BIT #$08        ; Got go-signal?
         BEQ C33673      ; Exit if not
         LDA $22         ; Timer expired?
         BEQ C33675      ; Dequeue if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$17        ; On MS: BGs+OBJ
         JSR C33677      ; Unhide 4 lines
         STA $33CA,X     ; Save scanline
         DEC $22         ; Anim timer -1
C33673:  SEC             ; Set to requeue
         RTS             ; Exit
C33675:  CLC             ; Set to dequeue
         RTS

; Enable or disable desired layers on next 4 lines below
C33677:  STA $9A09,Y     ; MS desig L1
         INY             ; Scanline +1
         STA $9A09,Y     ; MS desig L2
         INY             ; Scanline +1
         STA $9A09,Y     ; MS desig L3
         INY             ; Scanline +1
         STA $9A09,Y     ; MS desig L4
         INY             ; Scanline +1
         TYA             ; Line number
         RTS

; Enable or disable desired layers on next 4 lines above
C3368D:  STA $9A09,Y     ; MS desig L4
         DEY             ; Scanline -1
         STA $9A09,Y     ; MS desig L3
         DEY             ; Scanline -1
         STA $9A09,Y     ; MS desig L2
         DEY             ; Scanline -1
         STA $9A09,Y     ; MS desig L1
         DEY             ; Scanline -1
         TYA             ; Line number
         RTS

; Set to condense BG3 text in main menu
C336A3:  LDY #C336C2     ; Source LBs
         JMP bg3v        ; Queue BG3 V-Pan

; 65: Shift screen left or right
C336E7:  LDA $20         ; Timer expired?
         BNE C336EF      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C336EF:  REP #$21        ; 16-bit A; C-
         LDA $35         ; BG1 X-Pos
         ADC $9C         ; Add scroll speed
         STA $35         ; Set BG1 X-Pos
         STA $39         ; Set BG2 X-Pos
         STA $3D         ; Set BG3 X-Pos
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for non-shifted Status menu
C336FF:  LDY #C3370E     ; C3/370E
         JMP C305FE      ; Load navig data

; Handle D-Pad for non-shifted Status menu
C33705:  JSR C3072D      ; Handle D-Pad
C33708:  LDY #C33713     ; C3/3713
         JMP C30640      ; Relocate cursor

; Load navigation data for Config page 1
C33858:  LDY #C33867     ; C3/3867
         JMP C305FE      ; Load navig data

; Handle D-Pad for Config page 1
C3385E:  JSR C3072D      ; Handle D-Pad
C33861:  LDY #C3386C     ; C3/386C
         JMP C30640      ; Relocate cursor

; Load navigation data for Config page 2
C3387E:  LDY #C3388D     ; C3/388D
         JMP C305FE      ; Load navig data

; Handle D-Pad for Config page 2
C33884:  JSR C3072D      ; Handle D-Pad
C33887:  LDY #C33892     ; C3/3892
         JMP C30640      ; Relocate cursor

; Draw Config menu, load navigation data, create arrow
C3389E:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #$FFFB      ; Y: -5
         STY $3F         ; Set BG3 Y-Pos
         JSR C36A28      ; Clear BG2 map A
         LDX #C339E2     ; C3/39E2
         JSR boxes_      ; Upload windows
         JSR C3395E      ; Load gauge colors
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR C3C2F7      ; Color: Blue
         LDY #C349A1     ; Text pointer
         JSR C302F9      ; Draw "Config"
         JSR C35F34      ; Color: Blue
         LDX #C34993     ; Text ptrs loc
         LDA #$0C        ; Strings: 12
         JSR C369BA      ; Draw blue BG1 text
         JSR C3C2F2      ; Color: User's
         LDX #C34A28     ; Text ptrs loc
         LDA #$08        ; Strings: 8
         JSR C369BA      ; Draw Fast, etc.
         JSR C33B8C      ; Draw Active, Wait
         JSR C33BB7      ; Draw Bat.Spd nums
         JSR C33BF2      ; Draw Msg.Spd nums
         JSR C33C33      ; Draw Window, Short
         JSR C33C5C      ; Draw On and Off
         JSR C33C85      ; Draw Stereo, Mono
         JSR C33CB0      ; Draw Reset, Memory
         JSR C33CDB      ; Draw Optimum, Empty
         JSR C33D06      ; Draw Single/Multiple
         JSR C33FFD      ; Draw M.Order options
         JSR C340EA      ; Draw skin numbers
         JSR C34133      ; Draw skin palette
         JSR C341C3      ; Draw RGB info
         JSR C339F5      ; Get nav data; BG1 Y
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E6E      ; Upload BG3 A+B
         LDY #C33980     ; C3/3980
         JMP qanim1      ; Queue arrow OAM

; Draw empty color gauges
C33950:  JSR txt30       ; Color: Gray
         LDX #C34A22     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JMP C369BA      ; Draw text

; Load color gauge palette
C3395E:  LDA #$40        ; CGRAM: $0080
         STA $2121       ; To BG pal 4
         LDX $00         ; Color index: 0
C33965:  REP #$20        ; 16-bit A
         LDA $D8E880,X   ; Font color
         STA $7E30C9,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$0020      ; Done 16 colors?
         BNE C33965      ; Loop if not
         RTS

; Update arrow in Config menu
C33980:  BNE C339AB      ; If mode 1

; Mode 0: Initialize arrow
C33988:  LDY #C339CB     ; Anim table ptr
         JSR anm_c3      ; Set arrow's
         LDY #$1878      ; Pos: 120, 24
         JSR objpos      ; Set arrow's
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C339AB:  TXY             ; Queue index
         LDX $00         ; Arrow: Down
         LDA $4A         ; On first page?
         BEQ C339B5      ; Branch if so
         INX #2          ; Arrow: Up
C339B5:  REP #$20        ; 16-bit A
         LDA.L C339C7,X  ; Anim table ptr
         STA $32C9,Y     ; Set arrow's
         JMP oamsec      ; Set OAM; requeue

; Switch to Config page 2
C339EA:  LDY #$00FB      ; Y: 251
         STY $37         ; Set BG1 Y-Pos
         JSR C3387E      ; Load navig data
         JMP C33887      ; Relocate cursor

; Switch to Config page 1
C339F5:  LDY #$FFFB      ; Y: -5
         STY $37         ; Set BG1 Y-Pos
         JSR C33858      ; Load navig data
         JMP C33861      ; Relocate cursor

; 50: Scroll to Config page 2
C33A00:  LDA $20         ; Timer expired?
         BEQ C33A15      ; Finalize if so
         LDA $4A         ; On page 2?...
         BNE C33A1C      ; Branch if so
         REP #$21        ; 16-bit A; C-
         LDA $37         ; BG1 Y-Pos
         ADC #$0010      ; Move 16 px down
         STA $37         ; Save changes
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C33A15:  LDA #$01        ; Screen: 2nd
         STA $4A         ; Set active page
         JSR C339EA      ; Switch screens
C33A1C:  BRA C33A47      ; Next: Sustain menu

; 51: Scroll to Config page 1
C33A21:  LDA $20         ; Timer expired?
         BEQ C33A36      ; Finalize if so
         LDA $4A         ; On page 1?...
         BEQ C33A47      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $37         ; BG1 Y-Pos
         SEC             ; Prepare SBC
         SBC #$0010      ; Move 16 px up
         STA $37         ; Save changes
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C33A36:  STZ $4A         ; Page: 1st
         LDY #$FFFB      ; Y: -5
         STY $37         ; Set BG1 Y-Pos
         JSR C33858      ; Load navig data
         LDA #$08        ; Row: Controller
         STA $4E         ; Set cursor row
         JSR C33861      ; Relocate cursor
C33A47:  LDA #$0E        ; C3/22C5
         STA $26         ; Next: Sustain menu
         RTS

; Set Window 2 positions per scanline for Config menu
C33A4C:  LDY #C33A7A     ; C3/3A7A
C33A4_:  STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$01        ; 2Rx1B to PPU
         STA $4350       ; Set DMA mode
         LDA #$28        ; $2128, $2129
         STA $4351       ; To Win 2 L+R
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Set Window 2 positions for main menu
C33A6B:  LDA #$20        ; Channel: 5
         TRB $43         ; Halt HDMA-5
         LDX #$F708      ; Win2-L: 8
         STX $2128       ; Win2-R: 247
         RTS

; Window 2 positions per scanline for Config menu
C33A7A:  db $27,$FF,$FF  ; 39 lines: 255, 255
         db $50,$08,$F7  ; 80 lines: 8, 247
         db $50,$08,$F7  ; 80 lines: 8, 247
         db $10,$FF,$FF  ; 16 lines: 255, 255
         db $00          ; End

; Upload skin graphics, load colors and tile attributes
C33A87:  LDY #$7800      ; $7800
         STY $14         ; Set VRAM ptr
         LDA $1D4E       ; Skin, etc.
         JSR C33B30      ; Set source
         LDA $1D4E       ; Skin, etc.
         LDX #$0060      ; To 7E/312B
         JSR C33B5B      ; Load colors
         LDY #$1C00      ; Palette: 7
         JMP C30326      ; Build skin map

; Upload skin for save file 1
C33AA1:  LDY #$7A00      ; $7A00
         STY $14         ; Set VRAM ptr
         LDA $30674E     ; Skin, etc.
         LDY $91         ; Blank file?
         BNE C33AB1      ; Branch if not
         TDC             ; Use skin 1
C33AB1:  JSR C33B30      ; Set source
         JSR C31488      ; Upload skin
         LDY #$1820      ; Tile+32, pal 6
         JMP C30326      ; Build skin map

; Upload skin for save file 2
C33ABD:  LDY #$7C00      ; $7C00
         STY $14         ; Set VRAM ptr
         LDA $30714E     ; Skin, etc.
         LDY $93         ; Blank file?
         BNE C33ACD      ; Branch if not
         TDC             ; Use skin 1
C33ACD:  JSR C33B30      ; Set source
         JSR C31488      ; Upload skin
         LDY #$1440      ; Tile+64, pal 5
         JMP C30326      ; Build skin map

; Upload skin for save file 3
C33AD9:  LDY #$7E00      ; $7E00
         STY $14         ; Set VRAM ptr
         LDA $307B4E     ; Skin, etc.
         LDY $95         ; Blank file?
         BNE C33AE9      ; Branch if not
         TDC             ; Use skin 1
C33AE9:  JSR C33B30      ; Set source
         JSR C31488      ; Upload skin
         LDY #$1060      ; Tile+96, pal 4
         JMP C30326      ; Build skin map

; Load skin colors for save file 1
C33AF5:  LDA $30674E     ; Skin, etc.
         LDY $91         ; Blank file?
         BNE C33B00      ; Branch if not
         TDC             ; Use skin 1
C33B00:  LDX #$0040      ; To 7E/310B
         JSR C33B5B      ; Load colors
         JMP C314D2      ; Refresh CGRAM

; Load skin colors for save file 2
C33B09:  LDA $30714E     ; Skin, etc.
         LDY $93         ; Blank file?
         BNE C33B14      ; Branch if not
         TDC             ; Use skin 1
C33B14:  LDX #$0020      ; To 7E/30EB
         JSR C33B5B      ; Load colors
         JMP C314D2      ; Refresh CGRAM

; Load skin colors for save file 3
C33B1D:  LDA $307B4E     ; Skin, etc.
         LDY $95         ; Blank file?
         BNE C33B28      ; Branch if not
         TDC             ; Use skin 1
C33B28:  LDX $00         ; To 7E/30CB
         JSR C33B5B      ; Load colors
         JMP C314D2      ; Refresh CGRAM

; Set source for uploading skin graphics
C33B30:  AND #$0F        ; Skin number
         LDY #$0380      ; Skin data size
         JSR mul16       ; Skin x size
         STX $16         ; Set as src LBs
         LDA #$ED        ; Bank: ED
         STA $18         ; Set src HB
         LDY #$0400      ; Bytes: 1024
         STY $12         ; Set data size
         RTS

; Apply player's skin colors
C33B5B:  AND #$0F        ; Skin number
         XBA             ; Put in B
         LDA #$0E        ; Palette size
         JSR mul8        ; Skin x size
         TAY             ; Index product
         LDA #$0E        ; Colors: 7
C33B7E:  PHA             ; Save counter
         LDA $1D57,Y     ; Player color
         STA $7E30CB,X   ; Put in palette
         INY             ; Src index +1
         INX             ; Dst index +1
         PLA             ; Colors left
         DEC A           ; One less left
         BNE C33B7E      ; Loop till last
         RTS

; Draw Bat.Mode settings
C33B8C:  JSR C3808A      ; Color: Gray
         JSR C33BA5      ; Draw "Active"
         JSR C33BAE      ; Draw "Wait"
         JSR C3C2F2      ; Color: User's
         LDA $1D4D       ; Game options
         AND #$08        ; Wait mode?
         BNE C33BAE      ; Branch if so

; Fork: Draw "Active"
C33BA5:  LDY #C349F1     ; Text pointer
         JMP C302F9      ; Draw "Active"

; Fork: Draw "Wait"
C33BAE:  LDY #C34918     ; Text pointer
         JMP C302F9      ; Draw "Wait"

; Draw Bat.Speed values
C33BB7:  JSR C3808A      ; Color: Gray
         LDY #C3496E     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         JSR C3C2F2      ; Color: User's
         TDC             ; Clear A
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C33BE6,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         JMP C34116      ; Draw user speed

; Draw Msg.Speed values
C33BF2:  JSR C3808A      ; Color: Gray
         LDY #C3497C     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         JSR C3C2F2      ; Color: User's
         TDC             ; Clear A
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C33C27,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; Now 0-7
         JMP C34116      ; Draw user speed

; Draw Cmd.Set settings
C33C33:  JSR C3808A      ; Color: Gray
         JSR C33C4A      ; Draw "Short"
         JSR C33C53      ; Draw "Window"
         JSR C3C2F2      ; Color: User's
         LDA $1D4D       ; Window mode?
         BPL C33C53      ; Branch if so

; Fork: Draw "Short"
C33C4A:  LDY #C3492D     ; Text pointer
         JMP C302F9      ; Draw "Short"

; Fork: Draw "Window"
C33C53:  LDY #C349FA     ; Text pointer
         JMP C302F9      ; Draw "Window"

; Draw Gauge settings
C33C5C:  JSR C3808A      ; Color: Gray
         JSR C33C73      ; Draw "On"
         JSR C33C7C      ; Draw "Off"
         JSR C3C2F2      ; Color: User's
         LDA $1D4E       ; Gauges off?
         BMI C33C7C      ; Branch if so

; Fork: Draw "On"
C33C73:  LDY #C34935     ; Text pointer
         JMP C302F9      ; Draw "On"

; Fork: Draw "Off"
C33C7C:  LDY #C3493A     ; Text pointer
         JMP C302F9      ; Draw "Off"

; Draw Sound settings
C33C85:  JSR C3808A      ; Color: Gray
         JSR C33C9E      ; Draw "Stereo"
         JSR C33CA7      ; Draw "Mono"
         JSR C3C2F2      ; Color: User's
         LDA $1D4E       ; Game options
         AND #$20        ; Mono?
         BNE C33CA7      ; Branch if so

; Fork: Draw "Stereo"
C33C9E:  LDY #C34940     ; Text pointer
         JMP C302F9      ; Draw "Stereo"

; Fork: Draw "Mono"
C33CA7:  LDY #C34949     ; Text pointer
         JMP C302F9      ; Draw "Mono"

; Draw Cursor settings
C33CB0:  JSR C3808A      ; Color: Gray
         JSR C33CC9      ; Draw "Reset"
         JSR C33CD2      ; Draw "Memory"
         JSR C3C2F2      ; Color: User's
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BMI C33CD2      ; Branch if so

; Fork: Draw "Reset"
C33CC9:  LDY #C34A03     ; Text pointer
         JMP C302F9      ; Draw "Reset"

; Fork: Draw "Memory"
C33CD2:  LDY #C34950     ; Text pointer
         JMP C302F9      ; Draw "Memory"

; Draw Reequip settings
C33CDB:  JSR C3808A      ; Color: Gray
         JSR C33CF4      ; Draw "Optimum"
         JSR C33CFD      ; Draw "Empty"
         JSR C3C2F2      ; Color: User's
         LDA $1D4E       ; Game options
         AND #$10        ; Optimum mode?
         BNE C33CFD      ; Branch if not

; Fork: Draw "Optimum"
C33CF4:  LDY #C34959     ; Text pointer
         JMP C302F9      ; Draw "Optimum"

; Fork: Draw "Empty"
C33CFD:  LDY #C34A0B     ; Text pointer
         JMP C302F9      ; Draw "Empty"

; Draw Controller settings
C33D06:  JSR C3808A      ; Color: Gray
         JSR C33D1D      ; Draw "Single"
         JSR C33D26      ; Draw "Multiple"
         JSR C3C2F2      ; Color: User's
         LDA $1D54       ; Solo mode?
         BMI C33D26      ; Branch if not

; Fork: Draw "Single"
C33D1D:  LDY #C34A13     ; Text pointer
         JMP C302F9      ; Draw "Single"

; Fork: Draw "Multiple"
C33D26:  LDY #C34963     ; Text pointer
         JMP C302F9      ; Draw "Multiple"

; Handle Config changes with D-Pad
C33D2F:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4A         ; On page 2?
         BNE .sound      ; Branch if so
         CPX #$000A      ; On "Sound"?
         BEQ .nosnd      ; Branch if so
.sound   JSR C30EA3      ; Sound: Cursor
.nosnd   LDA $0B         ; Semi-auto keys
         LSR A           ; Set C if right
         LDA $4A         ; On first page?
         BEQ C33D40      ; Branch if so
         JMP (C33D55,X)  ; Handle page 2
C33D40:  JMP (C33D43,X)  ; Handle page 1

; Jump table for updating game options
C33D43:  dw C33D61       ; Bat.Mode
         dw C33D7A       ; Bat.Speed
         dw C33DAB       ; Msg.Speed
         dw C33DE8       ; Cmd.Set
         dw C33E01       ; Gauge
         dw C33E1A       ; Sound
         dw C33E4E       ; Cursor
         dw C33E6D       ; Reequip
         dw C33E86       ; Controller
C33D55:  dw C33E9F       ; Mag.Order
         dw C33ECD       ; Window
         dw C33F01       ; Viewed color
         dw C33F3C       ; R
         dw C33F5B       ; G
         dw C33F7A       ; B

; Update Bat.Mode
C33D61:  LDA #$08        ; Bat.Mode bit
         TRB $1D4D       ; Mode: Active
         BCC .draw       ; If pushing left
         TSB $1D4D       ; Mode: Wait
.draw    JMP C33B8C      ; Redraw text

; Update Bat.Speed
C33D7A:  LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         TRB $1D4D       ; Clear in config
         BCC C33D95      ; If pushing left

; Fork: Bat.Speed +1
C33D8A:  CMP #$05        ; On "6"?
         BEQ C33D9E      ; Retain if so
         INC A           ; Speed +1
         BRA C33D9E      ; Apply changes

; Fork: Bat.Speed -1
C33D95:  BEQ C33D9E      ; Retain if "1"
         DEC A           ; Speed -1

; Fork: Apply Bat.Speed
C33D9E:  TSB $1D4D       ; Update config
         JMP C33BB7      ; Redraw values

; Update Msg.Speed
C33DAB:  PHP             ; Save Carry
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         TRB $1D4D       ; Clear in config
         LSR A           ; Put in b3-b5
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         LSR A           ; Now 0-5
         PLP             ; Pushing right?
         BCC C33DCA      ; Branch if not

; Fork: Msg.Speed +1
C33DBF:  CMP #$05        ; On "6"?
         BEQ C33DD3      ; Retain if so
         INC A           ; Speed +1
         BRA C33DD3      ; Apply changes

; Fork: Msg.Speed -1
C33DCA:  DEC A           ; Speed -1
         BPL C33DD3      ; Retain if > 0
         INC A           ; Speed +1

; Fork: Apply Msg.Speed
C33DD3:  JSR x16         ; Speed x 16
         TSB $1D4D       ; Update config
         JMP C33BF2      ; Redraw values

; Update Cmd.Set mode
C33DE8:  LDA #$80        ; Cmd.Set bit
         TRB $1D4D       ; Mode: Window
         BCC .draw       ; If pushing left
         TSB $1D4D       ; Mode: Short
.draw    JMP C33C33      ; Redraw options

; Update gauge mode
C33E01:  LDA #$80        ; Gauge bit
         TRB $1D4E       ; Gauge: On
         BCC .draw       ; If pushing left
         TSB $1D4E       ; Gauge: Off
.draw    JMP C33C5C      ; Redraw options

; Update sound mode
C33E1A:  LDA #$20        ; Sound mode bit
         TRB $1D4E       ; Mode: Stereo
         BCS C33E2F      ; If pushing right
         TDC             ; Volume: Stereo
         BRA C33E2_      ; Skip 2 lines
C33E2F:  TSB $1D4E       ; Mode: Mono
         LDA #$FF        ; Volume: Mono
C33E2_:  JSR C33E3F      ; Adjust volume
         JSR C30EA3      ; Sound: Cursor
         JMP C33C85      ; Redraw options

; Adjust volume based on sound mode (stereo = 0)
C33E3F:  STA $001301     ; Set sound mode
         LDA #$F3        ; SPC code: $0D61
         STA $001300     ; Set SPC command
         JSL $C50004     ; Update ports
         RTS

; Update Cursor mode
C33E4E:  LDA #$40        ; Cursor mode bit
         TRB $1D4E       ; Mode: Reset
         BCS C33E62      ; If pushing right
         JSR C348F7      ; Forget positions
         BRA C33E6_      ; Redraw options
C33E62:  TSB $1D4E       ; Mode: Memory
         JSR C37068      ; Reset positions
C33E6_:  JMP C33CB0      ; Redraw options

; Update Reequip mode
C33E6D:  LDA #$10        ; Reequip bit
         TRB $1D4E       ; Mode: Optimum
         BCC .draw       ; If pushing left
         TSB $1D4E       ; Mode: Empty
.draw    JMP C33CDB      ; Redraw options

; Update Controller mode
C33E86:  LDA #$80        ; Controller bit
         TRB $1D54       ; Mode: Single
         BCC .draw       ; If pushing left
         TSB $1D54       ; Mode: Multiple
.draw    JMP C33D06      ; Redraw options

; Update Mag.Order
C33E9F:  LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         TRB $1D54       ; Clear in config
         BCC C33EB7      ; If pushing left

; Fork: Mag.Order +1
C33EAC:  CMP #$05        ; On "6"?
         BEQ C33EC0      ; Retain if so
         INC A           ; Order +1
         BRA C33EC0      ; Apply changes

; Fork: Mag.Order -1
C33EB7:  BEQ C33EC0      ; Retain if "1"
         DEC A           ; Order -1

; Fork: Apply Mag.Order
C33EC0:  TSB $1D54       ; Update config
         JMP C33FFD      ; Redraw text

; Handle wallpaper selection
C33ECD:  LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         TRB $1D4E       ; Clear in cofig
         BCC C33EE5      ; If pushing left

; Fork: Pushing right
C33EDA:  CMP #$07        ; On "8"?
         BEQ C33EEE      ; Retain if so
         INC A           ; Skin number +1
         BRA C33EEE      ; Apply changes

; Fork: Pushing left
C33EE5:  BEQ C33EEE      ; Retain if "1"
         DEC A           ; Skin number -1

; Fork: Apply wallpaper
C33EEE:  TSB $1D4E       ; Update config
         JSR C340EA      ; Redraw values
         JSR C33A87      ; Refresh skin
         JMP C341C3      ; Draw RGB info

; Change viewed color in Config
C33F01:  PHP             ; Save Carry
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         TRB $1D54       ; Clear in config
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         LSR A           ; Now 0-7
         PLP             ; Pushing right?
         BCC C33F1C      ; Branch if not

; Fork: Move to next color
C33F11:  CMP #$07        ; On last color?
         BEQ C33F25      ; Retain if so
         INC A           ; Color number +1
         BRA C33F25      ; Apply changes

; Fork: Move to preceding color
C33F1C:  DEC A           ; Color number -1
         BPL C33F25      ; Retain if > 0
         INC A           ; Color number +1

; Fork: Apply selection
C33F25:  ASL A           ; Put in b1-b3
         ASL A           ; Put in b2-b4
         ASL A           ; Put in b3-b5
         TSB $1D54       ; Update config
         JSR C34133      ; Redraw arrow
         JMP C341C3      ; Draw RGB info

; Update red component of font or skin color
C33F3C:  PEA $0002       ; Color index: 2
         BRA C33F7_      ; Branch below

; Update green component of font or skin color
C33F5B:  PEA $0001       ; Color index: 1
         BRA C33F7_      ; Skip a line

; Update blue component of font or skin color
C33F7A:  PEI ($00)       ; Color index: 0
C33F7_:  PHP             ; Save Carry
         JSR C341FE      ; Separate RGB
         PLP             ; Pushing right?
         PLX             ; Comp index
         LDA $E0,X       ; Component
         BCC C33F8D      ; Branch if left
         CMP #$1F        ; Comp = 31?
         BEQ C33F93      ; Retain if so
         INC $E0,X       ; Component +1
         BRA C33F93      ; Apply changes
C33F8D:  BEQ C33F93      ; If comp = 0
         DEC $E0,X       ; Component -1
C33F93:  JSR C34221      ; Merge RGB
         BRA C33FC4      ; Apply changes

; Apply player's font color
C33F99:  LDY $1D55       ; User font color
C33F9_:  REP #$20        ; 16-bit A
         TYA             ; Color
         STA $7E304F     ; Set for FWF
         STA $7E3073     ; Set VWF color A
         STA $7E3077     ; Set VWF color B
         SEP #$20        ; 8-bit A
         RTS

; Apply player's skin colors after changes
C33FAD:  LDX $00         ; Dst index: 0
         REP #$20        ; 16-bit A
C33FB1:  LDA $1D57,Y     ; Player color
         STA $7E312B,X   ; Put in palette
         INY             ; Src index +1
         INY             ; Src index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         CPX #$000E      ; Done 7 colors?
         BNE C33FB1      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Apply player's skin or font colors after changes
C33FC4:  TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         XBA             ; Put in B
         LDA #$0E        ; Palette size
         JSR mul8        ; Skin x size
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C33FF2      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
;        CLC             ; Prepare ADC
         ADC $4216       ; Add product
         TAX             ; Index sum
         REP #$20        ; 16-bit A
         LDA $9A         ; Updated color
         STA $1D55,X     ; Set user color
         LDY $4216       ; Palette index
         JSR C33FAD      ; Recolor skin
         BRA C33FFA      ; Redraw RGB info

; Fork: Font
C33FF2:  LDY $9A         ; Updated color
         STY $1D55       ; Put in options
         JSR C33F99      ; Put in palettes
C33FFA:  JMP C341C3      ; Redraw RGB info

; Draw Mag.Order settings
C33FFD:  JSR C3808A      ; Color: Gray
         LDY #C34AA5     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         JSR C3C2F2      ; Color: User's
         TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         PHA             ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3402F,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         PLA             ; Mag.Order
         JSR C34116      ; Draw user value

; Fork: Draw all three spell types
C3403B:  TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
         LDY #$0003      ; Strings: 3
C3404C:  PHY             ; Save counter
         PHX             ; Save index
         JSR C34058      ; Draw string
         PLX             ; String index
         PLY             ; Strings left
         INX             ; Point to next
         DEY             ; One less left
         BNE C3404C      ; Loop till last
         RTS

; Draw current Mag.Order spell type
C34058:  JSR wm9E8B      ; WRAM: 7E/9E8B
         PHY             ; Save pos index
         TDC             ; Clear A
         LDA.L C340D2,X  ; Text pointer
         TAX             ; Index it
         LDY #$0008      ; Letters: 8
.loop    LDA.L C34AD3,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE .loop       ; Loop till last
         REP #$20        ; 16-bit A
         PLA             ; String slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C340CC-2,X; Tilemap ptr
         STA $7E9E89     ; Set position
         JMP C37FD_      ; Draw string

; Draw wallpaper values
C340EA:  JSR C3808A      ; Color: Gray
         LDY #C34A93     ; Text pointer
         JSR C302F9      ; Draw 1-8 in gray
         JSR C3C2F2      ; Color: User's
         TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         PHA             ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C34123,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         PLA             ; Skin number
C34116:  CLC             ; Prepare ADC
         ADC.B #!num1    ; Convert to text
         STA $F9         ; Add to string
         STZ $FA         ; End string
         STX $F7         ; Set position
         LDY #$00F7      ; Source LBS
         TDC             ; Source HB
         JMP C302FD      ; Draw user value

; Draw wallpaper palette and arrow in Config
C34133:  LDA #$3C        ; Palette 7
         STA $29         ; Set tile info
         LDY #C34AC9     ; Text pointer
         JSR C302F9      ; Draw palette
         LDY #C3419D     ; Text pointer
         JSR C302F9      ; Erase arrow
         JSR C3808A      ; Color: Gray
         JSR C3417F      ; Draw "Font"
         JSR C34186      ; Draw "Window"
         JSR C3C2F2      ; Color: User's
         TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C3417F      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3418D-2,X; Text pointer
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         JSR C302F9      ; Draw arrow

; Fork: Draw "Window"
C34186:  LDY #C34ABA     ; Text pointer
         JMP C302F9      ; Draw "Window"

; Fork: Draw "Font"
C3417F:  LDY #C34AB3     ; Text pointer
         JMP C302F9      ; Draw "Font"

; Draw RGB gauges and values in Config menu
C341C3:  JSR C33950      ; Reset gauges
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         XBA             ; Put in B
         LDA #$0E        ; Palette size
         JSR mul8        ; Skin x size
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C341E7      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         ADC $4216       ; Add product
         TAX             ; Index sum
         LDY $1D55,X     ; Skin color
         BRA C341EA      ; Skip a line
C341E7:  LDY $1D55       ; Font color
C341EA:  STY $9A         ; Memorize it
         JSR C341FE      ; Separate RGB
         JSR C34263      ; Draw B info
         JSR C341FE      ; Separate RGB
         JSR C34250      ; Draw G info
         JSR C341FE      ; Separate RGB
         BRA C3423D      ; Draw R info

; Separate RGB components for color in Config menu
C341FE:  LDA $9A         ; Color LB
         AND #$1F        ; Get red
         STA $E2         ; Memorize it
         LDA $9B         ; Color HB
         AND #$7C        ; Get blue
         LSR A           ; Shift bits
         LSR A           ; Now 0-31
         STA $E0         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $9A         ; Color
         AND #$03E0      ; Get green
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; ÷16
         LSR A           ; Now 0-31
         SEP #$20        ; 8-bit A
         STA $E1         ; Memorize it
         RTS

; Merge RGB components of updated color
C34221:  LDA $E0         ; Blue
         ASL A           ; x2
         ASL A           ; x4
         STA $E8         ; Memorize it
         LDA $E2         ; Red
         STA $E7         ; Memorize it
         TDC             ; Clear A
         LDA $E1         ; Green
         JSR x32r        ; x32
         ORA $E7         ; Add R&B
         STA $9A         ; Memorize it
         SEP #$20        ; 8-bit A
         RTS

; Draw value and fill gauge for red component
C3423D:  LDY #$452F      ; Tilemap ptr
         JSR C33519      ; Set gauge pos
         LDA $E2         ; Red value
         LDX #$4529      ; Tilemap ptr
         BRA C34276      ; Draw text

; Draw value and fill gauge for green component
C34250:  LDY #$45AF      ; Tilemap ptr
         JSR C33519      ; Set gauge pos
         LDA $E1         ; Green value
         LDX #$45A9      ; Tilemap ptr
         BRA C34276      ; Draw text

; Draw value and fill gauge for blue component
C34263:  LDY #$462F      ; Tilemap ptr
         JSR C33519      ; Set gauge pos
         LDA $E0         ; Blue value
         LDX #$4629      ; Tilemap ptr

; Draw value and fill gauge for color component
C34276:  PHA             ; Save value
         PHA             ; Do it again
         PHX             ; Save position
         JSR C304E0      ; Convert value
         PLX             ; Text position
         JSR C3C2F2      ; Color: User's
         JSR C304B6      ; Draw 2 digits
         JSR wm9E8B      ; WRAM: 7E/9E8B
         TDC             ; Clear A
         PLA             ; Color value
         LSR A           ; ÷2
         LSR A           ; ÷4
         TAX             ; Set counter
         BEQ C3429C      ; Branch if 0
C34294:  LDA.B #!bar8    ; Full tile char
         STA $2180       ; Add to string
         DEX             ; One less tile
         BNE C34294      ; Loop till last
C3429C:  PLA             ; Color component
         AND #$03        ; Extremity size
         TAX             ; Index it
         LDA.L C342BE,X  ; Partial tile
         STA $2180       ; Add to string
         JSR txt30       ; Color: Gray
         JMP C37FD_      ; Draw gauge

; Text characters for filling color gauge
C342BE:  db !bar0        ; Empty tile
         db !bar2        ; 1/4 full
         db !bar4        ; 2/4 full
         db !bar6        ; 3/4 full

; 47: Initialize Cmd.Set menu
C342C2:  JSR C3352F      ; Reset/Stop stuff
         JSR C3442C      ; Draw menu
         LDY #C3468E     ; C3/468E
         JSR bg3v        ; Set to shift text
         JSR C345B6      ; Load navig data
         JSR C345BF      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$48        ; C3/42DF
         STA $27         ; Queue: Pick char
         JMP C33541      ; BRT:1 + NMI

; 48: Handle Cmd.Set menu member selection
C342DF:  JSR C345BC      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C34310      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Selected member
         CMP #$04        ; Chose Arrange?
         BEQ C34326      ; Sort if so
         TAX             ; Index member
         LDA $69,X       ; Nobody there?
         BMI C3430A      ; Fail if so
         LDA $4E         ; Cursor row
         STA $64         ; Set member slot
         LDY #C3464A     ; C3/464A
         JSR C305FE      ; Load navig data
         JSR C345DA      ; Relocate cursor
         LDA #$62        ; C3/4338
         STA $26         ; Next: Cmd choice
         JMP C30EB2      ; Sound: Click

; Fork: Play buzzer
C3430A:  JSR C3B66F      ; Buzzer + Mosaic

; Fork: Handle B and Start
C34310:  LDA $09         ; No-autofire keys
         BIT #$90        ; Using Start or B?
         BEQ C34375      ; Exit if not
         LDA #$0D        ; C3/1C7D
         STA $27         ; Queue Config
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Reset command order
C34326:  JSR C30EB2      ; Sound: Click
         JSR C30F39      ; Queue text upload
         JSR C343D0      ; Reset member 1
         JSR C343D8      ; Reset member 2
         JSR C343E1      ; Reset member 3
         JMP C343EA      ; Reset member 4

; 62: Handle Cmd.Set menu command choice 1
C34338:  JSR C34602      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C34359      ; Branch if not
         LDA $4B         ; Cursor slot
         STA $28         ; Set blinker's
         JSR C32F06      ; Create blinker
         LDA #$63        ; C3/4376
         STA $26         ; Next: Choice 2
         TDC             ; Clear A
         LDA $64         ; Selected member
         JSR C32D0_      ; Actor's address
         STY $67         ; Memorize it
         JMP C30EB2      ; Sound: Click

; Fork: Handle B
C34359:  LDA $09         ; Pushing B?
         BPL C34375      ; Exit if not
         JSR C345B6      ; Load navig data
         LDA $64         ; Return position
         STA $4E         ; Set cursor row
         JSR C345BF      ; Relocate cursor
         LDA #$48        ; C3/42DF
         STA $26         ; Next: Pick char
         JMP C30EA9      ; Sound: Cursor
C34375:  RTS

; 63: Handle Cmd.Set menu command choice 2
C34376:  JSR C34602      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C343BD      ; Branch if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; Cursor's slot
         REP #$21        ; 16-bit A; C-
         ADC $67         ; Add actor's adr
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $16,X       ; Second command
         PHA             ; Memorize it
         TDC             ; Clear A
         LDA $28         ; Blinker's slot
         REP #$21        ; 16-bit A; C-
         ADC $67         ; Add actor's adr
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $0016,Y     ; First command
         XBA             ; Move it to B
         PLA             ; Second command
         STA $0016,Y     ; Replace first
         XBA             ; First command
         STA $16,X       ; Replace second
         JSR C344B4      ; Draw char 1 text
         JSR C344ED      ; Draw char 2 text
         JSR C34526      ; Draw char 3 text
         JSR C3455F      ; Draw char 4 text
         JSR C30F39      ; Queue text upload
         BRA C343C6      ; Next: Choice 1

; Fork: Handle B
C343BD:  LDA $09         ; Pushing B?
         BPL C343CF      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C343C6:  LDA #$05        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$62        ; C3/4338
         STA $26         ; Next: Choice 1
C343CF:  RTS

; Reset command list for member 1
C343D0:  LDX $00         ; Point to $6D
         JSR C343F3      ; Reset commands
         JMP C344B4      ; Redraw text

; Reset command list for member 2
C343D8:  LDX #$0002      ; Point to $6F
         JSR C343F3      ; Reset commands
         JMP C344ED      ; Redraw text

; Reset command list for member 3
C343E1:  LDX #$0004      ; Point to $71
         JSR C343F3      ; Reset commands
         JMP C34526      ; Redraw text

; Reset command list for member 4
C343EA:  LDX #$0006      ; Point to $73
         JSR C343F3      ; Reset commands
         JMP C3455F      ; Redraw text

; Reset member's battle command list
C343F3:  LDY $6D,X       ; Actor's address
         BEQ C3442B      ; Exit if nobody
         JSR gogo2       ; Gogo?
         BEQ C3442B      ; Exit if so
         XBA             ; Put actor in B
         LDA #$16        ; Actor data size
         JSR mul8        ; Actor x size
         TAX             ; Index product
         REP #$20        ; 16-bit A
         LDA $ED7CA2,X   ; Commands 1+2
         STA $0016,Y     ; Set actor's
         LDA $ED7CA4,X   ; Commands 3+4
         STA $0018,Y     ; Set actor's
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
C3442B:  RTS

; Draw Cmd.Set menu
C3442C:  JSR C36A28      ; Clear BG2 map A
         LDX #C34490     ; C3/4490
         JSR boxes_      ; Upload windows
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR txt30       ; Color: Blue
         LDY #C34AF1     ; Text pointer
         JSR C302F9      ; Draw "Arrange"
         JSR C344B4      ; Draw char 1 text
         JSR C344ED      ; Draw char 2 text
         JSR C34526      ; Draw char 3 text
         JSR C3455F      ; Draw char 4 text
         JSR C30E28      ; Upload BG1 A+B
         JMP C30E6E      ; Upload BG3 A+B
C34525:  RTS

; Draw Cmd.Set menu text for member 1
C344B4:  LDA $69         ; Actor in slot
         BMI C34525      ; Exit if none
         PEA $79AD       ; Pos for cmd 1
         PEA $7A23       ; Pos for cmd 2
         PEA $7A37       ; Pos for cmd 3
         PEA $7AAD       ; Pos for cmd 4
;        PEA $7A0F       ; Pos for class
         PEA $798F       ; Pos for actor
         LDX $6D         ; Actor's address
         BRA C3455_      ; Draw text

; Draw Cmd.Set menu text for member 2
C344ED:  LDA $6A         ; Actor in slot
         BMI C34525      ; Exit if none
         PEA $7B6D       ; Pos for cmd 1
         PEA $7BE3       ; Pos for cmd 2
         PEA $7BF7       ; Pos for cmd 3
         PEA $7C6D       ; Pos for cmd 4
;        PEA $7BCF       ; Pos for class
         PEA $7B4F       ; Pos for actor
         LDX $6F         ; Actor's address
         BRA C3455_      ; Draw text

; Draw Cmd.Set menu text for member 3
C34526:  LDA $6B         ; Actor in slot
         BMI C34525      ; Exit if none
         PEA $7D2D       ; Pos for cmd 1
         PEA $7DA3       ; Pos for cmd 2
         PEA $7DB7       ; Pos for cmd 3
         PEA $7E2D       ; Pos for cmd 4
;        PEA $7D8F       ; Pos for class
         PEA $7D0F       ; Pos for actor
         LDX $71         ; Actor's address
         BRA C3455_      ; Draw text

; Draw Cmd.Set menu text for member 4
C3455F:  LDA $6C         ; Actor in slot
         BMI C34525      ; Exit if none
         PEA $7EED       ; Pos for cmd 1
         PEA $7F63       ; Pos for cmd 2
         PEA $7F77       ; Pos for cmd 3
         PEA $7FED       ; Pos for cmd 4
;        PEA $7F4F       ; Pos for class
         PEA $7ECF       ; Pos for actor
         LDX $73         ; Actor's address
C3455_:  STX $67         ; Memorize it
         JSL $C20006     ; Load gear data
         JSR txt30       ; Color: Blue
         PLY             ; Text position
         JSR C334CF      ; Draw actor name
         JSR C3C2F2      ; Color: User's
;        PLY             ; Text position
;        JSR C334E5      ; Actor class...
         PLY             ; Text position
cmdx4:   JSR C345AD      ; Draw command 4
         PLY             ; Text position
         JSR C345A5      ; Draw command 3
         PLY             ; Text position
         JSR C3459E      ; Draw command 2
         PLY             ; Text position

; Draw member's 1st command
C34598:  JSR C33519      ; Set pos/WRAM/Y
         BRA C345B3      ; Draw command

; Draw member's 2nd command
C3459E:  JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         BRA C345B3      ; Draw command

; Draw member's 3rd command
C345A5:  JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         BRA C345B3      ; Draw command

; Draw member's 4th command
C345AD:  JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         INY             ; Point to cmd 4
C345B3:  JMP C35EE1      ; Draw command

; Load navigation data for Cmd.Set menu's actor list
C345B6:  LDY #C345C5     ; C3/45C5
         JMP C305FE      ; Load navig data

; Handle D-Pad for Cmd.Set menu's actor list
C345BC:  JSR C3072D      ; Handle D-Pad
C345BF:  LDY #C345CA     ; C3/45CA
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 1
C345EA:  LDY #C3464F     ; C3/464F
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 2
C345F0:  LDY #C34657     ; C3/4657
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 3
C345F6:  LDY #C3465F     ; C3/465F
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 4
C345FC:  LDY #C34667     ; C3/4667
         JMP C30640      ; Relocate cursor

; Handle D-Pad and cursor for Cmd.Set menu's command list
C34602:  JSR C34615      ; Handle D-Pad
C345DA:  TDC             ; Clear A
         LDA $64         ; Member
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3460D,X)  ; Relocate cursor

; Jump table for the above
C3460D:  dw C345EA       ; Member 1
         dw C345F0       ; Member 2
         dw C345F6       ; Member 3
         dw C345FC       ; Member 4

; Handle D-Pad for Cmd.Set menu's command list
C34615:  STZ $4D         ; Cursor col: 1st
         LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C34622      ; Branch if not
         STZ $4E         ; Cursor slot: Top
         JSR C30EA3      ; Sound: Cursor
C34622:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3462F      ; Branch if not
         LDA #$03        ; Slot: Bottom
         STA $4E         ; Set cursor slot
         JSR C30EA3      ; Sound: Cursor
C3462F:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C3463C      ; Branch if not
         LDA #$01        ; Slot: Left
         STA $4E         ; Set cursor slot
         JSR C30EA3      ; Sound: Cursor
C3463C:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C346AC      ; Exit if not
         LDA #$02        ; Slot: Right
         STA $4E         ; Set cursor slot
         JMP C30EA3      ; Sound: Cursor
C346AC:  RTS

; 4B: Initialize Controller menu
C346AD:  JSR C3352F      ; Reset/Stop stuff
         JSR C346F5      ; Draw menu
         LDY #C348C7     ; C3/48C7
         JSR C33A4_      ; Queue Win2 HDMA
         LDY #C348E6     ; C3/48E6
         JSR C305FE      ; Load navig data
         JSR C348E0      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$4C        ; C3/46CA
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 4C: Sustain Controller menu
C346CA:  JSR C30F39      ; Queue BG3 upload
         JSR C348DD      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$90        ; Using Start or B?
         BEQ C346E6      ; Branch if not
         LDA #$0D        ; C3/1C7D
         STA $27         ; Queue Config menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle left and right
C346E6:  LDA $0B         ; Semi-auto keys
         BIT #$03        ; Using left/right?
         BEQ C346AC      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C346AC      ; Exit if so
         JSR C30EA3      ; Sound: Cursor
         TXA             ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3472A,X)  ; Apply changes

; Jump table for controller assignments
C3472A:  dw C34732       ; Member 1
         dw C34751       ; Member 2
         dw C34772       ; Member 3
         dw C34793       ; Member 4

; Draw Controller menu
C346F5:  LDX #C348F3     ; C3/48F3
         JSR C30341      ; Draw menu window
         JSR C30E52      ; Upload window
         JSR txt30       ; Color: Blue
         LDY #C34AFB     ; Text pointer
         JSR C302F9      ; Draw "Controller"
         JSR C347B4      ; Draw char 1 text
         JSR C347F1      ; Draw char 2 text
         JSR C3482E      ; Draw char 3 text
         JSR C3486B      ; Draw char 4 text
         JMP C30E6E      ; Upload text

; Update controller assignment for member 1
C34732:  LDA #$01        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C34747      ; Branch if not
         INC $1D4F       ; Assign Cntlr2
C34747:  BRA C347B4      ; Redraw text

; Update controller assignment for member 2
C34751:  LDA #$02        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C34767      ; Branch if not
         LDA #$02        ; Assign Cntlr2
         TSB $1D4F       ; Update settings
C34767:  BRA C347F1      ; Redraw text

; Update controller assignment for member 3
C34772:  LDA #$04        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C34788      ; Branch if not
         LDA #$04        ; Assign Cntlr2
         TSB $1D4F       ; Update settings
C34788:  JMP C3482E      ; Redraw text

; Update controller assignment for member 4
C34793:  LDA #$08        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C347A9      ; Branch if not
         LDA #$08        ; Assign Cntlr2
         TSB $1D4F       ; Update settings
C347A9:  JMP C3486B      ; Redraw text

; Draw Controller menu text for member 1
C347B4:  LDA $69         ; Nobody here?
         BMI C347F0      ; Exit if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         JSR C3C2F2      ; Color: User's
         LDY #$7BCF      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         LSR A           ; Player 1's?
         BCC C347D6      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C347DF      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C347E8      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C347D6:  LDA #$20        ; Color: User's
         JSR C347DF      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C347E8      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C347DF:  STA $29         ; Set palette
         LDY #C34B08     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C347E8:  STA $29         ; Set palette
         LDY #C34B11     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"
C347F0:  RTS

; Draw Controller menu text for member 2
C347F1:  LDA $6A         ; Nobody here?
         BMI C347F0      ; Exit if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         JSR C3C2F2      ; Color: User's
         LDY #$7C4F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$02        ; Player 1's?
         BEQ C34813      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C3481C      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C34825      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C34813:  LDA #$20        ; Color: User's
         JSR C3481C      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C34825      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C3481C:  STA $29         ; Set palette
         LDY #C34B1A     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C34825:  STA $29         ; Set palette
         LDY #C34B23     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"

; Draw Controller menu text for member 3
C3482E:  LDA $6B         ; Nobody here?
         BMI C347F0      ; Exit if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         JSR C3C2F2      ; Color: User's
         LDY #$7CCF      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$04        ; Player 1's?
         BEQ C34850      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C34859      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C34862      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C34850:  LDA #$20        ; Color: User's
         JSR C34859      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C34862      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C34859:  STA $29         ; Set palette
         LDY #C34B2C     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C34862:  STA $29         ; Set palette
         LDY #C34B35     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"

; Draw Controller menu text for member 4
C3486B:  LDA $6C         ; Nobody here?
         BMI C34B4F      ; Exit if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         JSR C3C2F2      ; Color: User's
         LDY #$7D4F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$08        ; Player 1's?
         BEQ C3488D      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C34896      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C3489F      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C3488D:  LDA #$20        ; Color: User's
         JSR C34896      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C3489F      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C34896:  STA $29         ; Set palette
         LDY #C34B3E     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C3489F:  STA $29         ; Set palette
         LDY #C34B47     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"

; Window 2 positions per scanline for Controller menu
C348C7:  db $27,$FF,$FF  ; 255, 255
         db $30,$08,$F7  ; 8, 247
         db $68,$FF,$FF  ; 255, 255
         db $10,$08,$F7  ; 8, 247
         db $10,$FF,$FF  ; 255, 255
         db $00          ; End

; Handle D-Pad for Controller menu
C348DD:  JSR C3072D      ; Handle D-Pad
C348E0:  LDY #C348EB     ; C3/48EB
         JMP C30640      ; Relocate cursor

; Forget memorized cursor positions for main menu
C348F7:  LDX #$001E      ; Position index
C348F9:  STZ $022B,X     ; Clear position
         DEX             ; Index -1
         BPL C348F9      ; Loop till < 0
C34B4F:  RTS

; Load navigation data for Skills menu
C34B50:  LDY #C34B6F     ; C3/4B6F
         JMP C305FE      ; Load navig data

; Handle D-Pad and cursor memory for Skills menu
C34B56:  JSR C3072D      ; Handle D-Pad
C34B59:  LDY #C34B74     ; C3/4B74
         JSR C30640      ; Relocate cursor
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $4D         ; Cursor position
         STA $0236,X     ; Remember it
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for Magic menu
C34B82:  LDY #C34BA9     ; C3/4BA9
         JMP C305FE      ; Load navig data

; Handle D-Pad and cursor memory for Magic menu
C34B88:  JSR C381C7      ; Handle D-Pad
C34B8B:  LDY #C34BAE     ; C3/4BAE
         JSR C30648      ; Relocate cursor
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4F         ; List column
         STA $023E,X     ; Remember it
         LDA $50         ; List row
         STA $023F,X     ; Remember it
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $4A         ; Scroll position
         STA $0246,X     ; Remember it
         RTS

; Load navigation data for SwdTech, Blitz, or Dance menu
C34BCE:  LDY #C34BDF     ; C3/4BDF
         JMP C305FE      ; Load navig data

; Handle D-Pad for SwdTech, Blitz, or Dance menu
C34BD4:  JSR C3072D      ; Handle D-Pad
C34BD7:  LDY #C34BE4     ; C3/4BE4
         JMP C30640      ; Relocate cursor

; Handle D-Pad for Lore menu
C34BFA:  JSR C381C7      ; Handle D-Pad
C34BFD:  LDY #C34C08     ; C3/4C08
         JMP C30648      ; Relocate cursor

; Handle D-Pad for Espers menu
C34C1E:  JSR C381C7      ; Handle D-Pad
C34C21:  LDY #C34C2C     ; C3/4C2C
         JMP C30648      ; Relocate cursor

; Handle D-Pad for Rage menu
C34C52:  JSR C381C7      ; Handle D-Pad
C34C55:  LDY #C34C60     ; C3/4C60
         JMP C30648      ; Relocate cursor

; Draw Skills menu, disable individual MP costs in Magic menu
C34C80:  STZ $9E         ; No MP by Magic
         JSR C30F89      ; Stop VRAM DMA B
         LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         JSR bg2b_cl     ; Clear BG2 A+B
         LDX #C34D98     ; C3/4D98
         JSR boxes_      ; Upload windows
         JSR C34D27      ; Draw actor info
         JSR C30E28      ; Upload BG1 A+B
         JSR bg3c_cl     ; Clear BG3 A-C
         JSR C3A662      ; Build desc map
         JSR C34D3D      ; Set skill colors
         LDX #$0006      ; 1st: Dance
.loop    PHX             ; Save skill index
         LDA $79,X       ; Text palette
         STA $29         ; Set attributes
         REP #$20        ; 16-bit A
         TXA             ; Skill index
         ASL A           ; Double it
         TAX             ; Reindex it
         LDA.L skillnm,X ; Text pointer
         TAY             ; Put it in Y
         JSR C302F9      ; Draw skill name
         PLX             ; Skill index
         DEX             ; Skill index -1
         BPL .loop       ; Loop till < 0
         JMP C30E6E      ; Upload BG3 A+B

; Draw actor info in Skills menu, including blue text
C34D27:  JSR bg1b_cl     ; Clear BG1 A+B
         JSR C35F34      ; Color: Blue
         LDX #C35C81     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         JMP C34EE5      ; Draw actor info

; Assign a palette to each submenu in Skills menu
C34D3D:  LDA #$24        ; Gray palette
         LDX #$0006      ; 1st: Dance
C34D41:  STA $79,X       ; Disable menu
         DEX             ; Menu slot -1
         BPL C34D41      ; Loop till Espers
         JSR C32D03      ; Actor's address
         LDX #$0004      ; Commands: 4
C34D50:  PHX             ; Save counter
         LDX #$0006      ; 1st: Dance
C34D53:  LDA $0016,Y     ; Actor's command
         CMP.L C34D78,X  ; Unlocks submenu?
         BNE C34D60      ; Skip menu if not
         LDA #$20        ; Color: User's
         STA $79,X       ; Enable menu
C34D60:  DEX             ; Menu slot -1
         BPL C34D53      ; Loop till Espers
         INY             ; Cmd slot +1
         PLX             ; Loop counter
         DEX             ; One less cmd
         BNE C34D50      ; Loop till last
         JSR gogo1       ; Actor = Gogo?
         BNE C34D77      ; Exit if not
         LDA #$24        ; Gray palette
         STA $79         ; Disable Espers
C34D77:  RTS

; Battle commands that unlock a skill menu
C34D78:  db $02          ; Magic (unlocks Espers)
         db $02          ; Magic (unlocks Magic)
         db $07          ; SwdTech
         db $0A          ; Blitz
         db $0C          ; Lore
         db $10          ; Rage
         db $13          ; Dance

; Draw Magic list and blue "MP…" and create portrait
C34D7F:  JSR C36A15      ; Clear BG1 map A
         JSR C34F1C      ; Build spell list
         JSR C34F87      ; Draw spell list
         JSR C3C2F7      ; Color: Blue
         LDY #C35C87     ; Text pointer
         JSR C302F9      ; Draw "MP…"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Set to condense text in Skills menu or submenu
C34DBC:  LDY #C34E26     ; Source LBs
         JSR bg3v        ; Queue BG3 V-Pan
         JSR C34E2D      ; Load BG1 V-Data
         LDX #$000C      ; Base index
C34DDF:  LDA.L C34E72,X  ; BG1 H-Pan data
         STA $7E9A09,X   ; Save in RAM
         DEX             ; Index -1
         BPL C34DDF      ; Loop till < 0
         LDY #$9A09      ; Src: 7E/9A09
         JSR bg1h_       ; Queue BG1 H-Pan
         LDY #$9849      ; Src: 7E/9849
         JMP bg1v_       ; Queue BG1 V-Pan

; Load vertical shift values for BG1 text in skill menus
C34E2D:  LDX $00         ; Index: 0
C34E2F:  LDA.L C34E7F,X  ; Stats V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At skills?
         BNE C34E2F      ; Loop if not
C34E3D:  LDA.L C34E7F,X  ; Skill V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; Top BG1 row
         JSR x16         ; x16
         REP #$21        ; 16-bit A; C-
         ADC.L C34E7F,X  ; Add V-Data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$005A      ; Past list?
         BNE C34E3D      ; Loop if not
C34E63:  LDA.L C34E7F,X  ; Bottom V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$005E      ; End of table?
         BNE C34E63      ; Loop if not
         RTS

; Draw actor info in Skills menu
C34EE5:  JSR C32D03      ; Actor's address
         STY $67         ; Memorize it
         LDY #$42DD      ; Class/KO pos
         LDX #$4F50      ; Icon position
         JSR C33427      ; Display status
         LDY #C35CD1     ; Text pointer
         JSR C302F9      ; Draw HP's "/"
         LDY #C35CD5     ; Text pointer
         JSR C302F9      ; Draw MP's "/"
         LDX #C34F12     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
C34F08:  JSR C3C2F2      ; Color: User's
         LDY #$421D      ; Text position
         JMP C334E6      ; Draw held esper

; Build Magic list based on Mag.Order
C34F1C:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX #$0036      ; Spells: 54
         LDA #$FF        ; Spell: None
C34F27:  STA $2180       ; Add to list
         DEX             ; One less spell
         BNE C34F27      ; Loop till last
         TDC             ; Clear A
         TAY             ; List slot: 1
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
C34F37:  PHX             ; Save index
         LDA.L C34F49,X  ; Starting spell
         CMP #$FF        ; At terminator?
         BEQ C34F47      ; Exit if so
         JSR C34F61      ; Populate list
         PLX             ; Type index
         INX             ; Index +1
         BRA C34F37      ; Do next type
C34F47:  PLX             ; Unstack index
         RTS

; Starting spell for each Magic type, sorted based on Mag.Order
C34F49:  db $2D,$00,$18,$FF  ; 1: Cure, Fire, Scan
         db $2D,$18,$00,$FF  ; 2: Cure, Scan, Fire
         db $00,$18,$2D,$FF  ; 3: Fire, Scan, Cure
         db $00,$2D,$18,$FF  ; 4: Fire, Cure, Scan
         db $18,$2D,$00,$FF  ; 5: Scan, Cure, Fire
         db $18,$00,$2D,$FF  ; 6: Scan, Fire, Cure

; Add spells of given type to Magic list based on starting spell
C34F61:  LDX #$0018      ; Black spells: 24
         CMP #$00        ; Base = Fire?
         BEQ C34F78      ; Branch if so
         LDX #$0009      ; White spells: 9
         CMP #$2D        ; Base = Cure?
         BEQ C34F78      ; Branch if so
         LDX #$0015      ; Gray spells: 21
C34F78:  STX $E0         ; Set spells left
C34F7B:  TYX             ; List slot
         STA $7E9D89,X   ; Add spell there
         INC A           ; Spell number +1
         INY             ; List slot +1
         DEC $E0         ; One less spell
         BNE C34F7B      ; Loop till last
         RTS

; Draw Magic list
C34F87:  JSR C383F7      ; Define $E5, $E6
         LDA #$08        ; Rows left: 8
C34F8D:  PHA             ; Save counter
         JSR C34F9E      ; Draw 2 spells
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C34F8D      ; Loop till last
         RTS

; Draw a row of two spells in Magic menu
C34F9E:  LDX #$0003      ; X: 3
         JSR .recur      ; Draw spell A
         LDX #$0010      ; X: 16
.recur   JSR C34FB5      ; Define source
         JSR C34FC4      ; Draw spell B
         INC $E5         ; Menu slot +1
         RTS

; Set source for loading Magic name
C34FB5:  LDY.W #!mag_ns  ; Letters: 7
         STY $EB         ; Set src size
         LDY.W #!mag_np  ; E6/F567
         STY $EF         ; Set src LBs
         LDA.B #!mag_np!h; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw text in spell slot of Magic menu
C34FC4:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         LDA $9E         ; Show MP in list?
         BEQ C3503E      ; Branch if not
         JSR C350EC      ; Spell
         JSR C3514D      ; Handle graying
         JSR C350EC      ; Spell
         BEQ C3501A      ; Blank if none
         JSR C350A2      ; Spell mastery
         INC A           ; Fully learned?
         BNE C3501A      ; Blank if not

; Fork: Draw spell plus MP cost
C34FEB:  JSR C350EC      ; Spell
         JSR C38467      ; Load name
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         JSR C350EC      ; Spell
         JSR C3510D      ; Define MP cost
         JMP draw3n      ; Draw string

; Fork: Blank spell slot
C3501A:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA #$FF        ; Spell: None
         STA $7E9D89,X   ; Assign to slot
         JSR C351B9      ; Disable spell
         LDY.W #!mag_ns+4; Spaces: 11
         JMP spacedr     ; Draw 11 spaces

; Fork: Draw spell plus percentage
C3503E:  JSR C350EC      ; Spell
         BEQ C3501A      ; Blank if none
         JSR C350A2      ; Spell mastery
         CMP #$00        ; Zero?
         BEQ C3501A      ; Blank if so
         PHA             ; Memorize it
         JSR C350EC      ; Spell
         JSR C38467      ; Load name
         PLA             ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C35088      ; Branch if so
         JSR C304E0      ; Turn into text
         JSR C351B9      ; Disable spell
         JSR C3C2F7      ; Color: Bluish
         LDA.B #!3dot    ; Char: "…"
         STA $2180       ; Add to string
         JSR add2n       ; Add mastery
         LDA.B #!perc    ; Char: "%"
         STA $2180       ; Add to string
C35082:  JMP C37FD_      ; Draw string

; Fork: Draw spell name only
C35088:  JSR C350EC      ; Spell
         JSR C3514D      ; Handle graying
         LDY #$0004      ; Spaces: 4
         JSR spaces      ; Add to string
         BRA C35082      ; Draw string

; Get spell's mastery percentage
C350A2:  STA $E0         ; Save spell
         JSR gogo1       ; Actor = Gogo?
         BEQ C350C5      ; Branch if so
C350AE:  XBA             ; Put in B
         LDA #$36        ; Spell list size
         JSR mul8        ; Actor x size
         TDC             ; Clear A
         LDA $E0         ; Spell
         REP #$20        ; 16-bit A
         ADC $4216       ; Add product
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $1A6E,X     ; Spell mastery
         RTS

; Fork: Test all members for Gogo
C350C5:  TDC             ; Member slot: 1
C350C7:  STA $E1         ; Save cur member
         JSR C32D0_      ; Actor's address
         BEQ C350E2      ; Skip if nobody
         JSR gogo2       ; Gogo or higher?
         BCS C350E2      ; Skip if so
         JSR C350AE      ; Actor's mastery
         CMP #$FF        ; Fully learned?
         BEQ C350EB      ; Exit if so
C350E2:  TDC             ; Clear A
         LDA $E1         ; Member slot
         INC A           ; Member slot +1
         CMP #$04        ; Done all 4?
         BNE C350C7      ; Loop if not
         TDC             ; Mastery: 0
C350EB:  RTS

; Get processed list entry
C350EC:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell in slot
         CMP #$FF        ; Empty slot?
         RTS

; Compute spell data index
C350F5:  XBA             ; Put spell in B
         LDA #$0E        ; Data size
         JSR mul8        ; Spell x size
         TAX             ; Index product
         TDC             ; Clear A
         RTS

; Define spell's MP cost
C3510D:  PHA             ; Save spell
         JSR C350F5      ; Compute index
         LDA $C46AC5,X   ; Base MP cost
         STA $E0         ; Memorize it

; Fork: Step Mine
C3511A:  PLA             ; Spell
         CMP #$99        ; Step Mine?
         BNE C3512E      ; Branch if not
         LDA $021B       ; Hours played
         ASL A           ; Double them
         STA $E0         ; Set MP cost
         LDA $021C       ; Minutes played
         CMP #$1E        ; Under 30?
         BCC C3512E      ; Branch if so
         INC $E0         ; MP cost +1

; Fork: Economizer
C3512E:  LDA $11D7       ; Gear effects
         ASL A           ; Economizer's?
         BPL C3513A      ; Branch if not
         LDA #$01        ; MP cost: 1
         BRA C3514B      ; Put it in X

; Fork: Gold Hairpin
C3513A:  ASL A           ; Gold Hairpin?
         BPL C35148      ; Branch if not
         LDA $E0         ; MP cost
         INC A           ; Add one
         LSR A           ; Halve it
         BRA C3514B      ; Put it in X

; Fork: Normal MP cost
C35148:  LDA $E0         ; Base MP cost
C3514B:  TAX             ; Put it in X
         RTS

; Enable or disable spell in Magic menu
C3514D:  CMP #$2A        ; Warp?
         BEQ C3517B      ; Branch if so
C35155:  JSR C350F5      ; Compute index
         LDA $C46AC3,X   ; Spell properties
         LSR A           ; Usable in field?
         BCC C351B9      ; Disable if not
         JSR C350EC      ; Spell
         JSR C3510D      ; Define MP cost
         BRA C35188      ; Test MP and Imp

; Fork: Warp
C3517B:  STA $E3         ; Memorize spell
         LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C351B9      ; Disable if not
         LDA $E3         ; Spell number
         BRA C35155      ; Do basic checks

; Fork: Test Imp
C35188:  STX $E2         ; Save MP cost
         JSR C32D03      ; Define Y
         LDA $0014,Y     ; Actor's status
         AND #$20        ; Imp?
         BEQ C3519B      ; Branch if not
         JSR C350EC      ; Spell
         CMP #$23        ; Imp?
         BNE C351B9      ; Disable if not

; Fork: Test MP
C3519B:  LDX $0D,Y       ; Actor's MP
         CPX $E2         ; Below cost?
         BCC C351B9      ; Disable if so

; Fork: Enable spell
C351AC:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         JSR C3C2F2      ; Color: User's
         BRA C351B_      ; Enable spell

; Fork: Disable spell
C351B9:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         JSR C3808A      ; Color: Gray
C351B_:  STA $7E9E09,X   ; Disable spell
         RTS

; Draw MP cost in corner of Magic menu
C351C6:  JSR C3C2F2      ; Color: User's
         LDY #$81BF      ; Tilemap ptr
         JSR C33519      ; Set position
         JSR C3BFC2      ; Spell by cursor
         JSR C3510D      ; Define MP cost
draw2n:  JSR C304E0      ; Turn into text
draw2n_: JSR add2n       ; Add to string
         JMP C37FD_      ; Draw MP cost

; Draw Lore list and menu title, create portrait
C351F9:  JSR C36A15      ; Clear BG1 map A
         JSR C3523C      ; Draw Lore list
         JSR C3C2F7      ; Color: Blue
         LDY #C35C91     ; Text pointer
         JSR C302F9      ; Draw "Lore"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build Lore list
C3520F:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX $00         ; Index: 0
         STZ $E0         ; 1st: Condemned
C35219:  LDY #$0008      ; Lores left: 8
         LDA $1D29,X     ; 8 known lores
C3521F:  ROR A           ; Got current?
         PHA             ; Save 8 lores
         BCC C3522A      ; Blank if not
         LDA $E0         ; Lore number
         BRA C3522C      ; Skip a line
C3522A:  LDA #$FF        ; Esper: None
C3522C:  STA $2180       ; Add to list
         INC $E0         ; Lore number +1
         PLA             ; 8 known lores
         DEY             ; Lores left -1
         BNE C3521F      ; Loop till last
         INX             ; Point to next 8
         CPX #$0003      ; Done 24 lores?
         BNE C35219      ; Loop if not
         RTS

; Build and draw Lore list
C3523C:  JSR C3520F      ; Build Lore list
         JSR C383F7      ; Define $E5, $E6
         LDA #$08        ; Lores left: 8
C35245:  PHA             ; Save counter
         JSR C35256      ; Draw name, cost
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Lores left
         DEC A           ; One less left
         BNE C35245      ; Loop till last
         RTS

; Prepare to and draw Lore's name and MP cost
C35256:  JSR C3C2F2      ; Color: User's
         JSR C35266      ; Define source
         LDX #$0003      ; X: 3
         JSR C35275      ; Draw string
         INC $E5         ; Lore slot +1
         RTS

; Set source for loading Lore name
C35266:  LDY.W #!lor_ns  ; Letters: 10
         STY $EB         ; Set src size
         LDY.W #!lor_np  ; E6/F9FD
         STY $EF         ; Set src LBs
         LDA.B #!lor_np!h; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw Lore's name and MP cost
C35275:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; Lore in slot
         BEQ C352C0      ; Blank if none
         TXA             ; Lore slot
         JSR C38467      ; Load name
         LDA.B #!3dot    ; Char: "…"
         STA $2180       ; Add to string
         LDA $E5         ; Lore slot
         CLC             ; Prepare ADC
         ADC #$8B        ; Get attack ID
         JSR C3510D      ; Define MP cost
         JMP draw3n      ; Draw string

; Fork: Blank Lore slot
C352C0:  LDY.W #!lor_ns+4; Spaces: 14
         JMP spacedr     ; Draw 14 spaces

; Draw SwdTech list and menu title, create portrait
C352D7:  JSR C36A15      ; Clear BG1 map A
         JSR C3536E      ; Build tech list
         JSR C3C2F2      ; Color: User's
         JSR C352F4      ; Draw tech list
         JSR C3C2F7      ; Color: Blue
         LDY #C35CB8     ; Text pointer
         JSR C302F9      ; Draw "SwdTech"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Draw SwdTech list
C352F4:  JSR C383F7      ; Define $E5, $E6
         INC $E6         ; BG1 write row +1
         STZ $E5         ; Tech slot: 1
         LDA #$04        ; Rows left: 4
C352FE:  PHA             ; Save counter
         JSR C35311      ; Draw 2 names
         JSR e6add4      ; BG1 WR row +4
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C352FE      ; Loop till last
         RTS

; Draw a row of two SwdTechs
C35311:  LDX #$0003      ; X: 3
         JSR .recur      ; Draw tech A
         LDX #$0011      ; X: 17
.recur   JSR C35328      ; Define source
         JSR C35337      ; Draw tech B
         INC $E5         ; Tech slot +1
         RTS

; Set source for loading SwdTech name
C35328:  LDY.W #!swt_ns  ; Letters: 12
         STY $EB         ; Set src size
         LDY.W #!swt_np  ; CF/3C40
         STY $EF         ; Set src LBs
         LDA.B #!swt_np!h; Bank: CF
         STA $F1         ; Set src HB
C35336:  RTS

; Draw SwdTech name
C35337:  LDA $E6         ; BG1 write row
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; SwdTech in slot
         BEQ C35336      ; Abort if none
         JSR C38467      ; Load name
         JMP C37FD_      ; Draw name

; Draw Rage list and menu title, create portrait
C35391:  JSR C36A15      ; Clear BG1 map A
         JSR C353A7      ; Draw Rage list
         JSR C3C2F7      ; Color: Blue
         LDY #C35C98     ; Text pointer
         JSR C302F9      ; Draw "Rage"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build and draw Rage list
C353A7:  JSR C353C1      ; Build Rage list
         JSR C383F7      ; Define $E5, $E6
         LDA #$08        ; Rows left: 8
C353B0:  PHA             ; Save counter
         JSR C353EE      ; Draw 2 Rages
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C353B0      ; Loop till last
         RTS

; Build Rage list
C353C1:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX $00         ; Pack index: 0
         STZ $E0         ; Current: Guard
C353CB:  LDY #$0008      ; Rages left: 8
         LDA $1D2C,X     ; 8 known Rages
C353D1:  ROR A           ; Got current?
         PHA             ; Save 8 Rages
         BCC C353DC      ; Blank if not
         LDA $E0         ; Rage number
         BRA C353DE      ; Skip a line
C353DC:  LDA #$FF        ; Rage: None
C353DE:  STA $2180       ; Add to list
         INC $E0         ; Rage number +1
         PLA             ; 8 known Rages
         DEY             ; Rages left -1
         BNE C353D1      ; Loop till last
         INX             ; Point to next 8
         CPX #$0020      ; Done 256 Rages?
         BNE C353CB      ; Loop if not
         RTS

; Draw a row of two Rages
C353EE:  JSR C3C2F2      ; Color: User's
         LDX #$0005      ; X: 5
         JSR .recur      ; Draw Rage A
         LDX #$0013      ; X: 19
.recur   JSR C35409      ; Define source
         JSR C35418      ; Draw Rage B
         INC $E5         ; Rage slot +1
         RTS

; Set source for loading enemy name
C35409:  LDY.W #!nme_ns  ; Letters: 10
         STY $EB         ; Set src size
         LDY.W #!nme_np  ; CF/C050
         STY $EF         ; Set src LBs
         LDA.B #!nme_np!h; Bank: CF
         STA $F1         ; Set src HB
         RTS

; Draw Rage name
C35418:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; Rage in slot
;        CMP #$FF        ; None or Pugs?
         BEQ C3543B      ; Blank if so
         TXA             ; Rage slot
         JSR C38467      ; Load name
         JMP C37FD_      ; Draw name

; Fork: Blank Rage slot
C3543B:  LDY.W #!nme_ns  ; Spaces: 10
         JMP spacedr     ; Draw 10 spaces

; Draw esper list and menu title, create portrait
C35452:  JSR C36A15      ; Clear BG1 map A
         JSR C3C2F2      ; Color: User's
         JSR C3546C      ; Draw esper list
         JSR C3C2F7      ; Color: Blue
         LDY #C35CA7     ; Text pointer
         JSR C302F9      ; Draw "Espers"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build and draw esper list
C3546C:  JSR C35486      ; Build esper list
         JSR C383F7      ; Define $E5, $E6
         LDA #$08        ; Rows left: 8
C35475:  PHA             ; Save counter
         JSR C354E3      ; Draw 2 espers
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C35475      ; Loop till last
         RTS

; Build sorted esper list
C35486:  LDX #$9DED      ; 7E/9DED
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Pack index: 0
         STZ $E0         ; Current: Ramuh
C35490:  LDY #$0008      ; Espers left: 8
         LDA $1A69,X     ; 8 owned espers
C35496:  ROR A           ; Got current?
         PHA             ; Save 8 espers
         BCC C354A1      ; Blank if not
         LDA $E0         ; Esper number
         BRA C354A3      ; Skip a line
C354A1:  LDA #$FF        ; Esper: None
C354A3:  STA $2180       ; Add to list
         INC $E0         ; Esper number +1
         PLA             ; 8 owned espers
         DEY             ; Espers left -1
         BNE C35496      ; Loop till last
         INX             ; Point to next 8
         CPX #$0004      ; Done 32 espers?
         BNE C35490      ; Loop if not

; Fork: Clear sorted list
C354B2:  JSR wm9D89      ; WRAM: 7E/9D89
         LDA #$FF        ; Esper: None
         LDX #$001D      ; Slots left: 29
C354BD:  STA $2180       ; Clear list slot
         DEX             ; One less left
         BNE C354BD      ; Loop till last

; Fork: Build sorted list
C354C3:  LDX #$9DED      ; 7E/9DED
         STX $2181       ; Set WRAM LBs
         LDY #$001B      ; Slots left: 27
         TDC             ; Clear A
C354CD:  LDA $2180       ; Esper in slot
         BMI C354DF      ; Skip if none
         PHA             ; Memorize it
         TAX             ; Index it
         LDA $D1F9B5,X   ; Intended slot
         DEC A           ; Subtract 1
         TAX             ; Index it
         PLA             ; Esper number
         STA $7E9D89,X   ; Add to new list
C354DF:  DEY             ; One less esper
         BNE C354CD      ; Loop till last
         RTS

; Draw a row of two esper names with MP cost
C354E3:  LDX #$0003      ; X: 3
         JSR .recur      ; Draw esper A
         LDX #$0011      ; X: 17
.recur   JSR C354FA      ; Define source
         JSR C35509      ; Draw esper B
         INC $E5         ; Esper slot +1
         RTS

; Set source for loading esper name
C354FA:  LDY.W #!esp_ns  ; Letters: 8
         STY $EB         ; Set src size
         LDY.W #!esp_np  ; E6/F6E1
         STY $EF         ; Set src LBs
         LDA.B #!esp_np!h; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw esper's name and MP cost
C35509:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; Esper in slot
         BEQ C3555D      ; Blank if none
         JSR C35574      ; Choose palette
         JSR C38467      ; Load name
         LDA.B #!3dot    ; Char: "…"
         STA $2180       ; Add to string
         JSR C350EC      ; Esper in slot
         CLC             ; Prepare ADC
         ADC #$36        ; Get attack ID
         JSR C3510D      ; Define MP cost
draw3n:  JSR C304E0      ; Turn into text
         LDA $F7         ; Hundreds digit
         STA $2180       ; Add to string
         JMP draw2n_     ; Add tens, ones

; Fork: Blank esper slot
C3555D:  LDY.W #!esp_ns+4; Spaces: 12
         JMP spacedr     ; Draw 12 spaces

; Define esper name color
C35574:  PHA             ; Save esper
         LDY #$001E      ; 1st: Guest 2
C3557B:  REP #$20        ; 16-bit A
         TYX             ; Actor index
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $1E,X       ; Actor's esper
         CMP $01,S       ; Matches ours?
         BEQ C35593      ; Gray out if so
         DEY             ; Actor index -1
         DEY             ; Actor index -1
         BPL C3557B      ; Loop till < 0
         LDA #$20        ; Color: User's
         BRA C35595      ; Skip a line
C35593:  LDA #$28        ; Color: Gray
C35595:  STA $29         ; Set palette
         PLA             ; Esper to draw
         RTS

; Draw "<actor> has it!" in esper data menu
C3559A:  JSR C3C2F2      ; Color: User's
         LDY #$40CD      ; Tilemap ptr
         JSR C33519      ; Set position
         LDY #$0006      ; Letters: 6
C355B2:  LDA $02,X       ; Name letter
         CMP #$FF        ; Terminator?
         BEQ C355C0      ; Done if so
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C355B2      ; Loop till last
C355C0:  LDX $00         ; Letter: 1st
C355C2:  LDA.L C35CD9,X  ; Message letter
         BEQ C355CE      ; Done if end
         STA $2180       ; Add to string
         INX             ; Point to next
         BRA C355C2      ; Do next letter
C355CE:  JMP C37FD_      ; Draw message

; Draw Blitz inputs and menu title, create portrait
C355D4:  JSR C36A15      ; Clear BG1 map A
         JSR C355EA      ; Draw inputs
         JSR C3C2F7      ; Color: Blue
         LDY #C35CB0     ; Text pointer
         JSR C302F9      ; Draw "Blitz"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build Blitz list and draw Blitz inputs
C355EA:  JSR C3561B      ; Build Blitz list
         JSR C383F7      ; Define $E5, $E6
         STZ $E5         ; Blitz slot: 1
         INC $E6         ; BG1 write row +1
         LDA #$04        ; Rows left: 4
C355F7:  PHA             ; Save counter
         JSR C3560A      ; Draw inputs x2
         JSR e6add4      ; BG1 WR row +4
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C355F7      ; Loop till last
         RTS

; Draw a row of two sets of Blitz inputs
C3560A:  LDX #$0004      ; X: 4
         JSR C35643      ; Draw inputs A
         INC $E5         ; Blitz slot +1
         LDX #$0012      ; X: 18
         JSR C35643      ; Draw inputs B
         INC $E5         ; Blitz slot +1
         RTS

; Build SwdTech list
C3536E:  LDA $1CF7       ; Known SwdTechs
         BRA C35623      ; Run Dance code

; Build Blitz list
C3561B:  LDA $1D28       ; Known Blitzes
         BRA C35623      ; Run Dance code

; Build Dance list
C35620:  LDA $1D4C       ; Known Dances
C35623:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX $00         ; 1st: Wind Song
         LDY #$0008      ; Dances left: 8
C3562E:  ROR A           ; Know current?
         PHA             ; Save 8 Dances
         BCC C35638      ; Blank if not
         TXA             ; Dance number
         BRA C3563A      ; Skip a line
C35638:  LDA #$FF        ; Dance: None
C3563A:  STA $2180       ; Add to list
         INX             ; Dance number +1
         PLA             ; Known Dances
         DEY             ; One less Dance
         BNE C3562E      ; Loop till last
C35642:  RTS

; Draw Blitz's inputs
C35643:  JSR wm9E8B      ; WRAM: 7E/9E8B
         LDA $E6         ; BG1 write row
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; Blitz in slot
         BEQ C35642      ; Abort if none

; Fork: Build tilemap for inputs
C35683:  XBA             ; Put Blitz in B
         LDA #$0C        ; Input data size
         JSR mul8        ; Blitz x size
         TAX             ; Index product
         REP #$20        ; 16-bit A
         LDA $7E9E89     ; Tilemap ptr
         STA $2181       ; Set WRAM LBs
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDY #$000A      ; Inputs: 10
C35699:  PHX             ; Save index
         LDA $C47A40,X   ; Blitz input
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C35C1C,X  ; Tile number
         STA $2180       ; Save in WRAM
         LDA.L C35C1C+1,X; Attributes
         STA $2180       ; Save in WRAM
         PLX             ; Input index
         INX             ; Input index +1
         DEY             ; One less input
         BNE C35699      ; Loop till last
         RTS

; Load esper description
C356DF:  JSR C35C09      ; Load pointers
         BRA C3572A      ; Load description

; Load Magic description
C356E5:  JSR C35BE3      ; Load pointers
         BRA C3572A      ; Load description

; Load Lore description
C356EB:  LDX.W #!lor_d_p ; ED/7A70
         STX $E7         ; Set ptr loc LBs
         LDX.W #!lor_d_l ; ED/77A0
         STX $EB         ; Set text loc LBs
         LDA.B #!lor_d_h ; Bank: ED
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         BRA C3572A      ; Load description

; Load SwdTech description
C35700:  LDX.W #!swt_d_p ; CF/FFAE
         STX $E7         ; Set ptr loc LBs
         LDX.W #!swt_d_l ; CF/FD00
         STX $EB         ; Set text loc LBs
         LDA.B #!swt_d_h ; Bank: CF
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         BRA C3572A      ; Load description

; Load Blitz description
C35715:  LDX.W #!btz_d_p ; CF/FF9E
         STX $E7         ; Set ptr loc LBs
         LDX.W #!btz_d_l ; CF/FC00
         STX $EB         ; Set text loc LBs
         LDA.B #!btz_d_h ; Bank: CF
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB

; Load skill or item description
C3572A:  JSR wm9EC9      ; WRAM: 7E/9EC9
C35730:  JSR C3BFC2      ; Skill or item
C35738:  CMP #$FF        ; Empty slot?
         BEQ C3576D      ; Blank if so
descld:  REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAY             ; Index it
         LDA [$E7],Y     ; Relative ptr
         TAY             ; Index it
         SEP #$20        ; 8-bit A
C35745:  LDA [$EB],Y     ; Text character
         STA $2180       ; Add to string
         INY             ; Index +1
         CMP #$00        ; Terminator?
         BNE C35745      ; Loop if not
         RTS

; Fork: Empty slot (space is for item usage menu)
C3576D:  STA $2180       ; Add a space
         STZ $2180       ; End string
         RTS

; Draw Dance list and menu title, create portrait
C35774:  JSR C36A15      ; Clear BG1 map A
         JSR C3578A      ; Draw Dance list
         JSR C3C2F7      ; Color: Blue
         LDY #C35C9F     ; Text pointer
         JSR C302F9      ; Draw "Dance"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build and draw Dance list
C3578A:  JSR C35620      ; Build Dance list
         JSR C3C2F2      ; Color: User's
         JSR C383F7      ; Define $E5, $E6
         INC $E6         ; BG1 write row +1
         STZ $E5         ; Dance slot: 1
         LDA #$04        ; Rows left: 4
C35797:  PHA             ; Save counter
         JSR C357AA      ; Draw 2 dances
         JSR e6add4      ; BG1 WR row +4
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C35797      ; Loop till last
         RTS

; Draw a row of two Dance names
C357AA:  LDX #$0003      ; X: 3
         JSR .recur      ; Draw Dance A
         LDX #$0011      ; X: 17
.recur   JSR C357C1      ; Define source
         JSR C357D0      ; Draw Dance B
         INC $E5         ; Dance slot +1
         RTS

; Set source for loading Dance name
C357C1:  LDY.W #!dnc_ns  ; Letters: 12
         STY $EB         ; Set src size
         LDY.W #!dnc_np  ; E6/FF9D
         STY $EF         ; Set src LBs
         LDA.B #!dnc_np!h; Bank: E6
         STA $F1         ; Set src HB
C357CF:  RTS

; Draw Dance name
C357D0:  LDA $E6         ; BG1 write row
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; Dance in slot
         BEQ C357CF      ; Abort if none
         JSR C38467      ; Load name
         JMP C37FD_      ; Draw name

; Set to delete portrait in Skills or Status menu
C35807:  TDC             ; Clear A
         LDA $60         ; Queue index
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Portrait: Off
         RTS

; Draw and upload spell usage menu
C35812:  JSR C36A28      ; Clear BG2 map A
         LDX #C3583F     ; C3/583F
         JSR boxes_      ; Upload windows
         JSR C36A19      ; Clear BG1 map B
         LDY #$FFC0      ; X: -64 = 448
         STY $35         ; Set BG1 X-Pos
         LDA #$02        ; Portrait row bit
         TSB $45         ; Ignore back row
         JSR C3318A      ; Draw party info
         JSR C3584B      ; Draw spell, cost
         JMP up_txt      ; Upload text maps

; Draw spell name and cost message for spell usage menu
C3584B:  JSR C3C2F2      ; Color: User's
         LDY #C35889     ; Text pointer
         JSR C302F9      ; Draw "MP"
         LDY #C3588E     ; Text pointer
         JSR C302F9      ; Draw "Needed"
         LDA $4B         ; Cursor slot
         STA $E5         ; Set spell slot
         JSR C34FB5      ; Define source
         LDY #$790D      ; Tilemap ptr
         JSR C33519      ; Set position
         JSR C350EC      ; Spell
         JSR C38467      ; Load spell name
         JSR C37FD_      ; Draw spell name
         JSR C350EC      ; Spell
         JSR C3510D      ; Define MP cost
         JSR C304E0      ; Turn into text
         LDX #$7A0F      ; Text position
         JMP C304B6      ; Draw 2 digits

; Initialize esper data menu
C35897:  LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         JSR C35B54      ; Load esper info
         JSR C3599F      ; Draw esper info
         JSR C30F11      ; Queue its upload
         JSR C31368      ; Upload it now
         JSR C30EFD      ; Requeue esper list
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9A10     ; Hide esper list
         SEP #$20        ; 8-bit A
         LDA $49         ; Top BG1 write row
         STA $5F         ; Save for return
         LDA #$07        ; BG1 VRAM row: 7
         STA $49         ; Save for V-Shift
         JSR C34E2D      ; Load V-shift data
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDY #C3598C     ; C3/598C
         JSR C305FE      ; Load navig data
         JMP C35986      ; Relocate cursor

; 4D: Sustain esper data menu
C358CE:  JSR C35983      ; Handle D-Pad
         JSR C35B93      ; Load description
         LDA $08         ; Pushing A?
         BPL C3590A      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; On esper name?
         BNE C3590A      ; Branch if not
         LDA $99         ; Viewed esper
         JSR C35574      ; Choose palette
         STA $E0         ; Memorize esper
         LDA $29         ; Esper palette
         CMP #$28        ; Grayed out?
         BNE C35902      ; Equip if not
         JSR C30EC0      ; Play buzzer
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C3559A      ; Draw who has it
         LDY #$0020      ; Frames: 32
         STY $20         ; Set exit delay
         LDA #$34        ; C3/293A
         STA $26         ; Next: Late exit
         JMP C30F11      ; Queue text upload

; Fork: Equip esper
C35902:  JSR C30EB2      ; Sound: Click
         JSR C32929      ; Equip/draw esper
         BRA C35913      ; Exit submenu

; Fork: Handle B
C3590A:  LDA $09         ; Pushing B?
         BPL C3597C      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C35913:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA $5F         ; Top BG1 write row
         STA $49         ; Restore it
         JSR C3546C      ; Draw esper list
         JSR C320B_      ; Create bar, etc.
         JSR oldcur      ; Restore cursor pos
         JSR C34C21      ; Relocate cursor
         JSR C30EFD      ; Queue list upload
         JSR C31368      ; Refresh esper list
         REP #$20        ; 16-bit A
         TDC             ; BG1 H-Shift: 0
         STA $7E9A10     ; Unhide esper list
         SEP #$20        ; 8-bit A
         JSR C34E2D      ; Load V-shift data
         JMP C30F11      ; Queue stats upload
C3597C:  RTS

; Handle D-Pad for esper data menu
C35983:  JSR C3072D      ; Handle D-Pad
C35986:  LDY #C35991     ; C3/5991
         JMP C30640      ; Relocate cursor

; Draw selected esper's info
C3599F:  JSR C3C2F2      ; Color: User's
         LDY #C35CEA     ; Text pointer
         JSR C302F9      ; Do "Learn.Rate"
         LDY #C35CE2     ; Text pointer
         JSR C302F9      ; Draw "Skill"
         LDA $99         ; Viewed esper
         JSR C35574      ; Choose palette
         LDY #$4411      ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         LDA $99         ; Viewed esper
         JSR drw_esp     ; Draw its name

; Fork: Draw spell data
C359D5:  JSR C3C2F2      ; Color: User's
         LDA $99         ; Viewed esper
         XBA             ; Put in B
         LDA #$0B        ; Esper data size
         JSR mul8        ; Esper x size
         TAX             ; Index product
         LDY #$0011      ; Y: 17
C359F4:  STY $F5         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $D86E00,X   ; Spell and rate
         STA $E0         ; Memorize them
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         PHX             ; Save index
         LDX #$0005      ; X: 5
;        LDY $F5         ; Y position
         LDA $E1         ; Spell
         PHA             ; Preserve it
         JSR C35AE1      ; Draw spell, rate
         LDX #$0018      ; X: 24
         LDY $F5         ; Y position
         PLA             ; Spell
         STA $E1         ; Restore it
         JSR C35A84      ; Draw percentage
         PLX             ; Spell data index
         LDY $F5         ; Y position
         INY             ; Y position +1
         INY             ; Y position +1
         CPY #$001B      ; Done 5 spells?
         BNE C359F4      ; Loop if not

; Fork: Draw esper bonus message
C35A29:  LDY #$4713      ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         LDA $D86E00,X   ; Esper bonus
         CMP #$FF        ; None?
         BEQ C35A67      ; Blank if so
         XBA             ; Put in B
         LDA.B #!esb_ns  ; Text length
         JSR mul8        ; Bonus x length
         LDX $00         ; Char index: 0
C35A43:  LDA.L C35CF7,X  ; "At..." char
         BEQ .skip       ; If terminator
         STA $2180       ; Add to string
         INX             ; Point to next
         BRA C35A43      ; Load next char
.skip    LDX $4216       ; Index product
         LDY.W #!esb_ns  ; Letters: 9
C35A56:  LDA.L !esb_np,X ; Bonus char
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C35A56      ; Loop till last
         JMP C37FD_      ; Draw string

; Fork: Blank esper bonus message
C35A67:  LDY #$0019      ; Spaces: 25
         JMP spacedr     ; Draw 25 spaces

; Draw spell's mastery percentage for esper data menu
C35A84:  JSR C35B3D      ; Compute map ptr
         JSR wm9E8B      ; WRAM: 7E/9E8B
         LDA $E1         ; Spell
         CMP #$FF        ; None?
         BEQ C35AD1      ; Blank if so
         JSR C350A2      ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C35AC2      ; Branch if so
         JSR C304E0      ; Turn into text
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         JSR add2n       ; Add mastery
C35AB7:  LDA.B #!perc    ; Char: "%"
         STA $2180       ; Add to string
C35ABC:  JMP C37FD_      ; Draw string

; Fork: Draw "100%"
C35AC2:  LDA.B #!num1    ; Char: "1"
         STA $2180       ; Add to string
         LDA.B #!num0    ; Char: "0"
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         BRA C35AB7      ; Add "%"; draw

; Fork: Blank percentage
C35AD1:  LDY #$0004      ; Spaces: 4
         JSR spaces      ; Add to string
         BRA C35ABC      ; Draw 4 spaces

; Draw spell's name and learning rate
C35AE1:  JSR C35B3D      ; Compute map ptr
C35AED:  JSR C34FB5      ; Define source
         LDA $E1         ; Spell
         CMP #$FF        ; None?
         BEQ C35B26      ; Blank if so
         JSR C38467      ; Load name
         LDA.B #!coln    ; Char: ":"
         STA $2180       ; Add to string
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         LDA.B #!mult    ; Char: "×"
         STA $2180       ; Add to string
         LDA $E0         ; Learning rate
         JMP draw2n      ; Draw string

; Fork: No spell
C35B26:  LDY #$000F      ; Spaces: 15
         JMP spacedr     ; Draw 15 spaces

; Compute position into BG1 tilemap B
C35B3D:  REP #$20        ; 16-bit A
         TYA             ; Y position
         JSR x64         ; x64
         STA $E7         ; Memorize it
         TXA             ; X position
         ASL A           ; Double it
         ADC $E7         ; Add Y x64
         ADC #$4049      ; Add base adr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         RTS

; Load esper's info for display
C35B54:  LDX #$AB8D      ; 7E/AB8D
         STX $2181       ; Set WRAM LBs
         LDA $99         ; Chosen esper
         STA $2180       ; Add to list
         XBA             ; Put in B
         LDA #$0B        ; Esper data size
         JSR mul8        ; Esper x size
         TAX             ; Index product
         LDY #$0005      ; Spells left: 5
C35B7B:  INX             ; Skip Learn.Rate
         LDA $D86E00,X   ; Spell taught
         STA $2180       ; Add to list
         INX             ; ROM index +1
         DEY             ; One less spell
         BNE C35B7B      ; Loop till last
         LDA $D86E00,X   ; Level up bonus
         STA $2180       ; Add to list
         RTS

; Load description for esper data menu
C35B93:  JSR wm9EC9      ; WRAM: 7E/9EC9
         TDC             ; Clear A
         LDA $4B         ; Cursor row
         TAX             ; Index it
         LDA $7EAB8D,X   ; Slot content
         CMP #$FF        ; Empty slot?
         BEQ C35BD1      ; Blank if so
         PHA             ; Memorize it
         JSR C35BDB      ; Load pointers
         PLA             ; Slot content
         JMP descld      ; Load desc

; Fork: Empty slot
C35BD1:  STZ $2180       ; End string
         RTS

; Load description pointers for esper data menu
C35BDB:  LDA $4B         ; On esper name?
         BEQ C35C09      ; Branch if so
         CMP #$06        ; On bonus?
         BEQ C35BF6      ; Branch if so

; Fork: Magic effect
C35BE3:  LDX.W #!mag_d_p ; D8/CF80
         STX $E7         ; Set ptr loc LBs
         LDX.W #!mag_d_l ; D8/C9A0
         STX $EB         ; Set text loc LBs
         LDA.B #!mag_d_h ; Bank: D8
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         RTS

; Fork: Level up bonus
C35BF6:  LDX.W #!esb_d_p ; ED/FFD0
         STX $E7         ; Set ptr loc LBs
         LDX.W #!esb_d_l ; ED/FE00
         STX $EB         ; Set text loc LBs
         LDA.B #!esb_d_h ; Bank: ED
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         RTS

; Fork: Esper effect
C35C09:  LDX.W #!esp_d_p ; CF/FE40
         STX $E7         ; Set ptr loc LBs
         LDX.W #!esp_d_l ; CF/3940
         STX $EB         ; Set text loc LBs
         LDA.B #!esp_d_h ; Bank: CF
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         RTS

; Tile attributes for Blitz inputs
C35C1C:  dw $0000        ; Terminator
         dw $0000        ; Bogus; for A
         dw $0000        ; Bogus; for B
         dw $2097        ; X
         dw $2098        ; Y
         dw $208B        ; L
         dw $2091        ; R
         dw $20D6        ; Down-left
         dw $A0D4        ; Down
         dw $60D6        ; Down-right
         dw $20D5        ; Right
         dw $C0D6        ; Up-right
         dw $20D4        ; Up
         dw $A0D6        ; Up-left
         dw $60D5        ; Left

; Draw and upload Status menu, create portrait
C35D05:  JSR C35D17      ; Draw main windows
         JSR C35DC1      ; Draw Gogo's panel
         JSR C35D3C      ; Draw blue text
         JSR C35F8D      ; Draw actor info
         JSR C35D77      ; Upload tilemaps
         JMP C361AC      ; Create portrait

; Draw windows for non-shifted Status menu
C35D17:  JSR C36A15      ; Clear BG1 map A
         JSR C36A23      ; Clear BG1 map D
         JSR bg3d_cl     ; Clear BG3 maps
         LDX #C35F79     ; C3/5F79
         JMP boxes       ; Draw windows

; Draw blue text and non-blue symbols in Status menu
C35D3C:  JSR C35D41      ; LV, HP, MP, %, /
         JSR C3C2F7      ; Color: Blue
         LDX #C36437     ; Text ptrs loc
         LDA #$0C        ; Strings: 12
         JMP C369BA      ; Draw stats, etc.

; Draw LV, HP, MP, and non-blue symbols in Status menu
C35D41:  JSR C3C2F2      ; Color: User's
         LDX #C3645B     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C369BA      ; Draw 2x / and %
         JSR C35F34      ; Color: Blue
         LDX #C36455     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JMP C369BA      ; Draw "LV/HP/MP"

; Upload common tilemaps (non-scrollable list)
C35D77:  JSR C30E52      ; Upload BG2 A+B
up_txt:  JSR C30E28      ; Upload BG1 A+B
up_bg3:  JSR C30E6E      ; Upload BG3 A+B
         JMP C30E7C      ; Upload BG3 C+D

; Handle member switching in Status menu
C35D83:  JSR C35D41      ; Draw "MP" + "/"
         JSR C35F8D      ; Draw actor info
         JSR C361A2      ; Create portrait
         JSR C30EFD      ; Queue BG1a upload
         JSR C30F61      ; Queue BG3a upload
         JSR C311B0      ; Swap portraits
         JSR C31368      ; Trigger NMI
         JSR C30F89      ; Dequeue BG3a
         LDY #$4800      ; $4800 = BG3c
         STY $14         ; Set VRAM ptr
         LDY #$8849      ; 7E/8849
         STY $16         ; Set src LBs
         JMP C31368      ; Upload BG3c

; Draw Gogo's list of available commands, prepare portrait hiding
C35DC1:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A

; Fork: Compile everyone's commands, exclude guests and dead Shadow
C35DC8:  TAX             ; 1st: Terra
C35DC9:  PHX             ; Save char slot
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY #$0004      ; Commands: 4
         LDA $1EDC       ; Eligible actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C35DFB      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
.loop1   LDA $16,X       ; Command
         STA $2180       ; Add to list
         INX             ; Point to next
         DEY             ; One less left
         BNE .loop1      ; Loop till 4th
         BRA C35E0B      ; Do next actor
C35DFB:  SEP #$20        ; 8-bit A
         LDA #$FF        ; Command: None
.loop2   STA $2180       ; Add to list
         DEY             ; One less left
         BNE .loop2      ; Loop till 4th
C35E0B:  PLX             ; Actor slot
         INX             ; Actor slot +1
         CPX #$0010      ; Done 16 actors?
         BNE C35DC9      ; Loop if not

; Fork: Delete duplicates
C35E12:  TDC             ; Clear A
         TAX             ; Cmd slot: 1
C35E14:  PHX             ; Save cmd slot
         LDA $7E9E09,X   ; Available cmd
C35E19:  CMP $7E9E0A,X   ; Duplicate?
         BNE C35E27      ; Branch if not
         PHA             ; Save command
         LDA #$FF        ; Command: None
         STA $7E9E0A,X   ; Clear duplicate
         PLA             ; Battle command
C35E27:  INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C35E19      ; Loop if not
         PLX             ; Base cmd slot
         INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C35E14      ; Loop if not

; Fork: Build final command list
C35E34:  JSR wm9D8A      ; WRAM: 7E/9D8A
         LDA #$FF        ; Cmd: Empty
         STA $2180       ; Add to list
         TDC             ; Clear A
         TAX             ; Cmd slot: 1
         TAY             ; Cmd count: 0
C35E42:  TDC             ; ...
         PHX             ; Save cmd slot
         LDA $7E9E09,X   ; Available cmd
         BMI C35E60      ; Skip if none
         CMP #$12        ; Mimic?
         BEQ C35E60      ; Skip if so
         STA $E0         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         LDA $CFFE00,X   ; Properties
         LSR A           ; Gogo can use?
         BCC C35E60      ; Skip if not
         LDA $E0         ; Command
         STA $2180       ; Add to list
         INY             ; Cmd count +1
C35E60:  PLX             ; Cmd slot
         INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C35E42      ; Loop if not
         INY             ; Cmd count +1
         TYA             ; Put it in A
         STA $7E9D89     ; Set list size

; Fork: Load window layout for command list
C35E6D:  LDX #$0007      ; Base index
C35E75:  LDA.L C35F85,X  ; Window data
         STA $7EAA8D,X   ; Save in RAM
         DEX             ; Index -1
         BPL C35E75      ; Loop till < 0

; Fork: Draw both segments of command window
C35E82:  TYA             ; Command count
         STA $E2         ; Memorize it
         ASL A           ; x2
         ADC $E2         ; x3
         AND #$FE        ; -1 if odd
         BEQ C35E90      ; Branch if no cmd
         INC A           ; +1
         INC A           ; +1
C35E90:  LSR A           ; ÷2
         STA $7EAA90     ; Set L-Win heigth
         STA $7EAA94     ; Set R-Win heigth
         LDX #$AA8D      ; 7E/AA8D
         LDA #$7E        ; Bank: 7E
         JSR C30343      ; Draw left box
         LDX #$AA91      ; 7E/AA91
;        LDA #$7E        ; ...
;        STA $E9         ; ...
         JSR C30345      ; Draw right box

; Fork: Draw command list, prepare portrait hiding
C35EAD:  LDA $7E9D89     ; List size
         STA $E5         ; Memorize it
         STZ $E6         ; Clear HB
         TDC             ; Clear A
         TAX             ; Cmd slot: 1
         LDY #$80C9      ; Tilemap ptr
C35EBA:  PHX             ; Save cmd slot
         PHY             ; Save position
         LDA $7E9D8A,X   ; Available cmd
         JSR C35ED7      ; Draw cmd name
         PLY             ; Text position
         REP #$21        ; 16-bit A; C-
         TYA             ; Put in A
         ADC #$0080      ; +2 rows down
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         PLX             ; Cmd slot
         INX             ; Cmd slot +1
         CPX $E5         ; End of list?
         BNE C35EBA      ; Loop if not

; Fork: Set a section of menu to mask wrapping Gogo portrait
C35F50:  LDX #$61CA      ; Tilemap ptr
         STX $E7         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dst HB
         LDX #$0006      ; Rows left: 6
C35F5C:  LDY $00         ; Map index: 0
         LDA #$3D        ; Pal 7, priority
C35F60:  STA [$E7],Y     ; Set attributes
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0012      ; Done 9 tiles?
         BNE C35F60      ; Loop if not
         REP #$21        ; 16-bit A; C-
         LDA $E7         ; Tilemap ptr
         ADC #$0040      ; Go 1 row down
         STA $E7         ; Save changes
         SEP #$20        ; 8-bit A
         DEX             ; One less row
         BNE C35F5C      ; Loop till last
         RTS

; Draw battle command name, ignore modifiers
C35ED7:  PHA             ; Save command
         JSR C33519      ; Set pos, WRAM
         PLA             ; Battle command
         BPL C35EE6      ; Draw it if any
C35F0C:  LDY.W #!cmd_ns  ; Spaces: 7
         JMP spacedr     ; Draw 7 spaces

; Draw battle command name, apply modifiers
C35EE1:  JSR C3612C      ; Apply modifiers
         BMI C35F0C      ; Blank if no cmd
C35EE6:  PHA             ; Save command
         JSR C35F25      ; Pick a palette
         PLA             ; Command
         XBA             ; Put in B
         LDX.W #!cmd_ns  ; Letters: 7
         LDA.B #!cmd_np!h; Text ptr HB
         LDY.W #!cmd_np  ; Text ptr LBs
         JSR fw_txt      ; Load name
C35F06:  JMP C37FD_      ; Draw cmd name

; Select a palette for battle command
C35F25:  CMP #$0B        ; Runic?
         BEQ C35F3A      ; Branch if so
         CMP #$07        ; SwdTech?
         BEQ C35F44      ; Branch if so
C35F2E:  JMP C3C2F2      ; Color: User's

; Fork: Handle Runic
C35F3A:  LDA $11DA       ; R-Hand can Runic?
         ORA $11DB       ; Or L-Hand?
         BPL C35F34      ; Gray out if not
         BRA C35F2E      ; Use user's color

; Fork: Handle SwdTech
C35F44:  LDA $11DA       ; R-Hand flags
         ORA $11DB       ; Add L-Hand's
         BIT #$02        ; Can use SwdTech?
         BNE C35F2E      ; User color if so

; Fork: Set to gray
C35F34:  LDA #$24        ; Palette 1
         STA $29         ; Color: Gray
         RTS

; Draw actor info in Status menu
C35F8D:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         ASL A           ; Double it
         TAY             ; Index it
         LDA $69,X       ; Actor
         LDX $6D,Y       ; Actor address
         STX $67         ; Memorize it
C35FC2:  JSL $C20006     ; Load properties
         LDY $67         ; Actor's address
         JSR C399E8      ; Set Bat.Pwr mode
         JSR C3C2F2      ; Color: User's
         PEA $8861       ; Pos for Mag.Pwr
         PEA $7FE1       ; Pos for Stamina
         PEA $7F61       ; Pos for Speed
         PEA $7EE1       ; Pos for Vigor
         PEA $7F7D       ; Pos for Evade
         PEA $887D       ; Pos for MBlock
         LDX #$000A      ; 1st: MBlock
.loop    STX $FE         ; Save stat index
         LDA $11A0,X     ; Stat value
         JSR C304E0      ; Turn into text
         PLX             ; Text position
         JSR C304C0      ; Draw 3 digits
         LDX $FE         ; Stat index
         DEX             ; Stat index -1
         DEX             ; Stat index -1
         BPL .loop       ; Loop till < 0
         JSR C39371      ; Define Bat.Pwr
         JSR C3052E      ; Turn into text
         LDX #$7E7D      ; Text position
         JSR C30486      ; Draw 3 digits
         LDA $11BA       ; Defense
         JSR C304E0      ; Turn into text
         LDX #$7EFD      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11BB       ; Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$7FFD      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDY #$398F      ; Text position
         JSR C334CF      ; Draw actor name
;        LDY #$399D      ; Text position
;        JSR C334E5      ; Actor class...
         LDY #$39B1      ; Text position
         JSR C334E6      ; Draw held esper
         JSR C36102      ; Draw commands
         JSR C3C2F2      ; Color: User's
         LDX #C36096     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         LDX $67         ; Actor's address
         LDY $11,X       ; Experience LBs
         STY $F1         ; Memorize them
         LDA $13,X       ; Experience HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         LDX #$7CD7      ; Text position
         JSR C304A3      ; Draw 8 digits
         JSR C360A0      ; Get needed exp
         JSR C30582      ; Turn into text
         LDX #$7DD7      ; Text position
         JSR C304A3      ; Draw 8 digits
         STZ $47         ; Ailments: Off
         JSR C311B0      ; Hide ail. icons
         JMP C3625B      ; Display status

; Calculate experience needed to level up
C360A0:  TDC             ; Clear A
         TAX             ; Clear X
         STX $F1         ; Needed XP LBs
         STX $F3         ; Needed XP HB
         LDX $67         ; Actor's address
         LDA $08,X       ; Level
         CMP #$63        ; 99?
         BEQ C36101      ; Zero if so
         JSR C360CA      ; Get needed XP
         LDX $67         ; Actor's address
         LDA $F1         ; Needed XP LBs
         SEC             ; Prepare SBC
         SBC $11,X       ; Deduct XP LBs
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         LDA $F3         ; Needed XP HB
         SBC $13,X       ; Deduct XP HB
         STA $F3         ; Save changes
         RTS

; Calculate total experience needed to level up
C360CA:  TAY             ; Levels left
         LDX $00         ; 1st: Level 1
C360D5:  REP #$21        ; 16-bit A; C-
         LDA $ED8220,X   ; Needed XP
         ADC $F1         ; Add total LBs
         STA $F1         ; Set total LBs
         BCC .next       ; If no overflow
         INC $F3         ; Total HB +1
.next    INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less level
         BNE C360D5      ; Loop till last

; Fork: Octuple total to get true value
C360F1:  LDX #$0003      ; Loop counter
.loop    ASL $F1         ; Total LBs x2
         ROL $F3         ; HBs x2 + C
         DEX             ; Counter -1
         BNE .loop       ; Loop till 0
C36101:  RTS

; Draw actor's command list in Status menu
C36102:  PEA $7BF1       ; Cmd1 position
         PEA $7C71       ; Cmd2 position
         PEA $7CF1       ; Cmd3 position
         LDY #$7D71      ; Cmd4 position
         JMP cmdx4       ; Draw cmd names

; Handle battle command modifiers
C3612C:  LDA $0016,Y     ; Command
         CMP #$02        ; Magic?
         BNE C3613D      ; Branch if not
         PHY             ; Save index
         JSR C30D2B      ; Can use magic?
         PLY             ; Actor's address
         BCS C3616F      ; Branch if so
         BRA C3616_      ; Command: None

; Fork: Morph
C3613D:  CMP #$03        ; Morph command?
         BNE C3614F      ; Branch if not
         LDA $1DD1       ; Event flags
         BIT #$04        ; Unlocked Morph?
         BNE C3616F      ; Branch if so
         BRA C3616_      ; Command: None

; Fork: Leap
C3614F:  CMP #$11        ; Leap command?
         BNE C36160      ; Branch if not
         LDA $11E4       ; Veldt flags
         BIT #$04        ; Can show Leap?
         BNE C3616F      ; Branch if so
         BRA C3616_      ; Command: None

; Fork: Dance
C36160:  CMP #$13        ; Dance command?
         BNE C3616F      ; Branch if not
         LDA $1D4C       ; Known Dances
         BNE C3616F      ; Branch if any
C3616_:  LDA #$FF        ; Command: None
         RTS

; Fork: Relic effects
C3616F:  LDA $0016,Y     ; Command
         STA $E0         ; Memorize it
         TDC             ; Clear A
         TAX             ; 1st: Capture
         LDA $11D6       ; Relic effects
         AND #$7C        ; Cmd upgrades
         ASL A           ; Shift bits
C3617C:  ASL A           ; Got current?
         BCC C36189      ; Skip if not
         PHA             ; Save upgrades
         LDA.L C36198,X  ; Cmd to switch
         CMP $E0         ; Current cmd?
         BEQ C36192      ; Replace if so
         PLA             ; Cmd upgrades
C36189:  INX             ; Index +1
         CPX #$0005      ; Done Fight?
         BNE C3617C      ; Loop if not
         LDA $E0         ; Original cmd
         RTS

; Fork: Replace command
C36192:  PLA             ; Clean stack
         LDA.L C3619D,X  ; New command
         RTS

; Commands to upgrade
C36198:  db $05          ; Steal
         db $0F          ; Slot
         db $0D          ; Sketch
         db $02          ; Magic
         db $00          ; Fight

; Command upgrades
C3619D:  db $06          ; Capture
         db $18          ; GP Rain
         db $0E          ; Control
         db $17          ; X Magic
         db $16          ; Jump

; Replace portrait in Status menu after actor swap
C361A2:  JSR C35807      ; Hide old one

; Create portrait by upper-left corner
C361AC:  JSR C361DA      ; Queue OAM fn
         BRA C361E6      ; Init sprite

; Create portrait for Equip or Relic menu
C361B2:  JSR C361DA      ; Queue OAM fn
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         LDY #$30C8      ; Pos: 200, 48
         JSR objpos      ; Set sprite's
;        TDC             ; Clear A
         LDA $28         ; Member slot
         TAY             ; Put in Y
         JSR C30ACC      ; Set anim ptr
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Create portrait A
C361DA:  LDY #C30B12     ; C3/0B12
         JSR qanim3      ; Queue OAM fn
         TXA             ; Queue index
         STA $60         ; Set sprite's
         RTS

; Place portrait by upper-left corner, set pose timer
C361E6:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         LDA $28         ; Member slot
         TAY             ; Put in Y
         JSR C30AF1      ; Set X position
         JSR C361FB      ; Set Y, ptr
         PLB             ; Restore DB
         RTS

; Initialize variables for portrait by upper-left corner
C361FB:  LDA #$38        ; Y: 56
         STA $344A,X     ; Set sprite's
         JMP C30ACC      ; Load anim ptr

; Set to condense BG3 text in Status menu
C3620B:  LDY #C3622A     ; Source LBs
         JMP bg3v        ; Queue BG3 V-Pan

; Display status effects in Status menu
C3625B:  LDY #$399D      ; Text position
         LDX #$2050      ; Icon position
         STX $E7         ; Set as current
         JSR C33519      ; Set text pos
         LDA $0014,Y     ; Wounded?
         BMI C362E7      ; Draw it if so
         AND #$70        ; Clear/Imp/Pet
         STA $E1         ; Memorize them
         LDA $0014,Y     ; Status effects
         AND #$07        ; Dark/Zom/Poison
         ASL A           ; Put in b1-b3
         STA $E2         ; Memorize them
         LDA $0015,Y     ; Status effects
         AND #$80        ; Isolate Float
         ORA $E1         ; Add Clear, etc.
         ORA $E2         ; Add Dark, etc.
         BEQ C362E1      ; Blank if none
         STZ $48         ; Icon fn mode: 0
         JSR icons       ; Create icons
C362E1:  LDY #$0008      ; Spaces: 8
         JSR spaces      ; Add to string
         JMP C37FD_      ; Blank "Wounded"

; Fork: Draw "Wounded"
C362E7:  LDX $00         ; Index: 0
C362EF:  LDA.L C3371B,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$0008      ; Copied 8?
         BNE C362EF      ; Loop if not
         JSR C3808A      ; Color: Gray
         JMP C37FD_      ; Draw string

; 42: Initialize Lineup's Status menu
C3631D:  JSR C3352F      ; Reset/Stop stuff
         LDA $0200       ; Menu number
         STA $22         ; Memorize it
;        STZ $0200       ; Actor arrows: Off...
;        STZ $25         ; Never read...
         LDA #$80        ; Channel: 7
         TRB $43         ; Halt HDMA-7
         JSR C3620B      ; Set to shift text
         JSR C36354      ; Draw menu; portrait
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$43        ; C3/633F
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 43: Sustain Lineup's Status menu
C3633F:  LDA $09         ; Pushing B?
         BPL C36378      ; Exit if not
         LDA #$7D        ; C3/7131
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         LDA $22         ; Former menu
         STA $0200       ; Set as current
         JMP C30EA9      ; Sound: Cursor

; Draw Lineup's Status menu, create portrait
C36354:  JSR C35D17      ; Draw windows
         JSR C35D3C      ; Draw blue text
         JSR C36379      ; Get actor address
         JSR C35FC2      ; Draw actor info
         JSR C35D77      ; Upload tilemaps
         JSR C361DA      ; Init portrait
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         LDA $28         ; Actor
         TAY             ; Index it
         JSR C3638E      ; Set portrait's X
         TDC             ; Clear A
         TAY             ; Portrait slot: 1
         JSR C361FB      ; Set Y, ptr
         PLB             ; Restore DB
C36378:  RTS

; Load actor number and address for Lineup's Status menu
C36379:  TDC             ; Clear A
         LDA $C9         ; Actor
         STA $28         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         STA $67         ; Memorize it
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $C9         ; Actor
         RTS

; Set portrait's X position for Lineup's Status menu
C3638E:  LDA $1850,Y     ; Actor info
         BIT #$20        ; Back row?
         BEQ C3639C      ; Branch if not
         LDA #$1A        ; X: 26
         BRA C363A1      ; Skip a line
C3639C:  LDA #$0E        ; X: 15
C363A1:  STA $33CA,X     ; Set sprite's
C363A6:  RTS

; 6A: Sustain shifted Status menu
C363A7:  JSR C36409      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C363DA      ; Branch if not
         JSR C30EB2      ; Sound: Click
         STZ $65         ; Edited slot HB
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Chosen command
         PHA             ; Memorize it
         JSR C32D03      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         ADC $64         ; Add edited slot
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         PLA             ; Chosen command
         STA $0016,Y     ; Assign to actor
         JSR C36102      ; Redraw commands
         BRA C363E3      ; Shift screen

; Fork: Handle B
C363DA:  LDA $09         ; Pushing B?
         BPL C363A6      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C363E3:  LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$0C        ; C3/21F5
         STA $27         ; Queue: Normal menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Shift screen
         JSR C336FF      ; Load navig data
         LDA $64         ; Old cursor row
         STA $4E         ; Set as current
         JMP C33708      ; Relocate cursor

; Handle D-Pad for shifted Status menu
C36409:  JSR C3072D      ; Handle D-Pad
C3640C:  LDY #C36417     ; C3/6417
         JMP C30640      ; Relocate cursor

; 5D: Initialize actor naming menu
C3652D:  JSR C3352F      ; Reset/Stop stuff
         LDY $0201       ; Actor's address
         STY $67         ; Memorize it
         JSR C36904      ; Reset BGs' X/Y
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         STZ $4A         ; Screen: 1st...
         LDY #C36647     ; C3/6647
         JSR C305FE      ; Load navig data
         JSR C36641      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C36705      ; Draw menu
         JSR C36621      ; Set arrow's column
         JSR C3683C      ; Set to shift text
         JSR C3678C      ; Get portrait colors
         JSR C36771      ; Upload portrait GFX
         JSR C366D8      ; Create portrait
         LDY #C368A3     ; C3/68A3
         JSR qanim2      ; Queue arrow OAM
         LDA #$5F        ; C3/656C
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 5F: Sustain actor naming menu
C3656C:  JSR C30EE9      ; Queue text upload
         JSR C3663E      ; Handle D-Pad
         JSR C3675B      ; Redraw actor name

; Fork: Handle Start
C36575:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BEQ C3657E      ; Branch if not
         LDY $67         ; Actor's address
         LDA $0002,Y     ; First letter
         INC A           ; Terminator?
         BNE C365DB      ; Valid if not
         JMP C3B66F      ; Buzzer + Mosaic
C365DB:  JSR C30EB2      ; Sound: Click
;        STZ $0205       ; Never read...
         JMP fdexit      ; Queue menu exit

; Fork: Handle A
C3657E:  LDA $08         ; Pushing A?
         BPL C36595      ; Branch if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Mode: Add
         JSR C365E8      ; Add letter
         LDA $28         ; Arrow's column
         CMP #$05        ; Rightmost?
         BEQ C36592      ; Exit if so
         INC A           ; Go right by 1
C36592:  STA $28         ; Save changes
         RTS

; Fork: Handle B
C36595:  LDA $09         ; Pushing B?
         BPL C365C1      ; Exit if not
         JSR C30EC7      ; Sound: Delete
         LDA $28         ; Arrow's column
         BEQ C365C1      ; Exit if first
         CMP #$05        ; Rightmost?
         BNE C365B5      ; Branch if not
         JSR C3660F      ; Define Y
         LDA $0002,Y     ; Letter 6
         CMP #$FF        ; Blank?
         BEQ C365B5      ; Branch if so
         LDA #$FF        ; Mode: Delete V1
         BRA C365E8      ; Delete letter 6

; Fork: Delete non-sixth letter
C365B5:  LDA #$01        ; Mode: Delete V2
         JSR C365E8      ; Delete letter
         DEC $28         ; Move arrow left
C365C1:  RTS

; Add or remove letter from actor name
C365E8:  PHA             ; Save mode
         JSR C3660F      ; Define Y
         PLA             ; Deleting 6th?
         BMI C365FA      ; Branch if so
         BEQ C36600      ; Branch if adding
         LDA #$FF        ; Char: Terminator
         STA $0001,Y     ; Clear last letter
         RTS

; Fork: Delete letter 6
C365FA:  LDA #$FF        ; Char: Terminator
         STA $0002,Y     ; Clear letter 6
         RTS

; Fork: Add selected letter
C36600:  TDC             ; Clear A
         LDA $4B         ; Selected slot
;        CLC             ; Prepare ADC
;        ADC $4A         ; For SFC...
         TAX             ; Index sum
         LDA.L !anm_ct,X ; Chosen letter
         STA $0002,Y     ; Add to name
         RTS

; Get index for overwritten letter in actor naming menu
C3660F:  LDY $67         ; Actor's address
         LDA $28         ; Arrow column
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         REP #$21        ; 16-bit A; C-
         TYA             ; Actor's address
         ADC $E7         ; Add column
         TAY             ; Put sum in Y
         SEP #$20        ; 8-bit A
         RTS

; Initialize arrow's column for actor naming menu
C36621:  LDX $67         ; Actor's address
         LDY $00         ; Column: 1st
C36625:  LDA $02,X       ; Current letter
         INC A           ; Terminator?
         BEQ C36634      ; Branch if so
         INX             ; Point to next
         INY             ; Arrow column +1
         CPY #$0006      ; Done 6 letters?
         BNE C36625      ; Loop if not
         DEY             ; Column: 6th
C36634:  TYA             ; Move column to A
         STA $28         ; Set arrow column
         RTS

; Handle D-Pad for actor naming menu
C3663E:  JSR C3072D      ; Handle D-Pad
C36641:  LDY #C3664C     ; C3/664C
         JMP C30640      ; Relocate cursor

; Create portrait for actor naming menu
C366D8:  LDY #C30B12     ; C3/0B12
         JSR qanim3      ; Queue OAM fn
         LDY #C30B8C     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         PEA $1010       ; Pos: 16, 16
         JMP C3E9DY      ; Set sprite's

; Draw actor naming menu
C36705:  JSR C36A28      ; Clear BG2 map A
         LDX #C36761     ; C3/6761
         JSR boxes_      ; Upload windows
         JSR bg1c_cl     ; Clear BG1 A-C
         JSR C3C2F2      ; Color: User's
         LDX #$399B      ; Tilemap ptr
         LDY.W #!anm_ct  ; D8/E8C8
         STY $E7         ; Set src LBs
         LDA.B #!anm_ct!h; Bank: D8
         STA $E9         ; Set src HB
         LDA #$07        ; Text rows: 7
         STA $E5         ; Set for options
         JSR C367BF      ; Draw options
         JSR C3675B      ; Draw actor name
         LDY #C368E3     ; Text pointer
         JSR C302F9      ; Draw "Please..."
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E44      ; Upload BG1 C+D
         JSR C36A3C      ; Clear BG3 map A
         JMP C30E6E      ; Upload BG3 A+B

; Draw actor name for actor naming menu
C3675B:  LDY #$4229      ; Text position
         JMP C334CF      ; Draw actor name

; Upload portrait for actor naming menu
C36771:  LDX $67         ; Actor's address
         TDC             ; Clear A
         LDA $01,X       ; Graphics set
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA #$2600      ; $2600
         STA $2116       ; Set VRAM ptr
         LDA.L C36F1B,X  ; GFX pointer
         TAX             ; Index it
         JSR C37000      ; Load portrait
         SEP #$20        ; 8-bit A
         RTS

; Load portrait colors for actor naming menu
C3678C:  LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDY $67         ; Actor's address
         TDC             ; Clear A
         LDA $0001,Y     ; Graphics set
         TAX             ; Index it
         LDA.L C36F00,X  ; Palette number
         JSR x32r        ; x32
         TAX             ; Index it
         LDY $00         ; RAM index: 0
C367A5:  REP #$20        ; 16-bit A
         PHX             ; Save ROM index
         LDA $ED5860,X   ; Portrait color
         TYX             ; RAM index
         STA $7E3149,X   ; To OBJ pal 0
         SEP #$20        ; 8-bit A
         PLX             ; ROM index
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E3         ; One less color
         BNE C367A5      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Draw options in actor naming menu
C367BF:  STX $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDY $00         ; ROM index: 0
C367C7:  LDA #$0A        ; Columns: 10
         STA $E6         ; Set counter
         LDX $00         ; RAM index: 0
C367CD:  LDA [$E7],Y     ; Character
         STA $E0         ; Memorize it
         PHY             ; Save ROM index

; Fork: Add character to tilemap
C367FC:  TXY             ; RAM index
         LDA $E0         ; Character
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PLY             ; ROM index
         INY             ; ROM index +1
         LDA $E6         ; Columns left
         CMP #$06        ; At separator?
         BNE C36827      ; Branch if not
         INX             ; RAM index +1
         INX             ; RAM index +1
C36827:  DEC $E6         ; One less column
         BNE C367CD      ; Loop till last
         REP #$21        ; 16-bit A; C-
         LDA $EB         ; Tilemap ptr
         ADC #$0080      ; +2 rows down
         STA $EB         ; Save changes
         SEP #$20        ; 8-bit A
         DEC $E5         ; One less row
         BNE C367C7      ; Loop till last
         RTS

; Set to condense text in actor naming menu
C3683C:  LDX #$000C      ; Base index
C3683E:  LDA.L C36896,X  ; BG1 V-Pan data
         STA $7E9BC9,X   ; Save in RAM
         DEX             ; Index -1
         BPL C3683E      ; Loop till < 0
         LDY #$9BC9      ; Src: 7E/9BC9
         JSR bg1v_       ; Queue BG1 V-Pan
         LDY #C36889     ; Source LBs
         LDA #$C3        ; Source HB
         JMP bg1h        ; Queue BG1 H-Pan

; Update arrow in actor naming menu
C368A3:  BNE C368CB      ; If mode 1

; Mode 0: Initialize arrow
C368AB:  LDY #C3B452     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         LDA #$40        ; Y: 64
         STA $344A,X     ; Set sprite's
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C368CB:  TXY             ; Queue index
         TDC             ; Clear A
         LDA $28         ; Arrow's slot
         TAX             ; Index it
         LDA.L C368DD,X  ; X position
         STA $33CA,Y     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue

; Reset menu or ending variables
C368FA:  JSL $D4CDF3     ; Reset many vars
         JSR C36904      ; Reset BGs' X/Y
         JMP C3A796      ; Clear VWF GFX

; Reset BG positions
C36904:  LDY $00         ; Clear Y
         STY $35         ; BG1 X-Loc: 0
         STY $39         ; BG2 X-Loc: 0
         STY $3D         ; BG3 X-Loc: 0
         STY $37         ; BG1 Y-Loc: 0
         STY $3B         ; BG2 Y-Loc: 0
         STY $3F         ; BG3 Y-Loc: 0
         STY $41         ; List V-Spd: 0
         RTS

; Get party info from SRAM block
C36915:  JSL $D4CA00     ; Clear all info
         TDC             ; Clear A
         TAY             ; 1st: Terra
C3691C:  LDA $1850,Y     ; Party info
         BIT #$40        ; Object's off?
         BEQ C36941      ; Skip if so
         AND #$07        ; Get party
         CMP $1A6D       ; Active party?
         BNE C36941      ; Skip if not
         LDA $1850,Y     ; Party info
         PHA             ; Memorize it
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         TAX             ; Index it
         PLA             ; Party info
         STA $75,X       ; Set member's
         TYA             ; Actor slot
         STA $69,X       ; Set member's
C36941:  INY             ; Actor slot +1
         CPY #$0010      ; Done 16 chars?
         BNE C3691C      ; Loop if not
         LDY $00         ; 1st: Member 1
C36949:  TDC             ; Clear A
         LDA $0069,Y     ; Actor
         CMP #$FF        ; Empty slot?
         BEQ C36962      ; Skip if so
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         PHA             ; Memorize it
         TYA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         PLA             ; SRAM address
         STA $6D,X       ; Set member's
         SEP #$20        ; 8-bit A
C36962:  INY             ; Member slot +1
         CPY #$0004      ; Done 4 slots?
         BNE C36949      ; Loop if not
         RTS

; SRAM block addresses for actor data
C36969:  dw $1600        ; 00: Terra
         dw $1625        ; 01: Locke
         dw $164A        ; 02: Cyan
         dw $166F        ; 03: Shadow
         dw $1694        ; 04: Edgar
         dw $16B9        ; 05: Sabin
         dw $16DE        ; 06: Celes
         dw $1703        ; 07: Strago
         dw $1728        ; 08: Relm
         dw $174D        ; 09: Setzer
         dw $1772        ; 0A: Mog
         dw $1797        ; 0B: Gau
         dw $17BC        ; 0C: Gogo
         dw $17E1        ; 0D: Umaro
         dw $1806        ; 0E: Guest 1
         dw $182B        ; 0F: Guest 2

; Copy party info to SRAM block
C36989:  LDX #$0003      ; 1st: Member 4
C3698C:  LDA $69,X       ; Actor in slot
         BMI C369A2      ; Skip if nobody
         TAY             ; Index it
         LDA $75,X       ; Party info
         AND #$E7        ; Clear roster slot
         STA $E0         ; Memorize info
         TXA             ; Member slot
         ASL A           ; Put in b1-b2
         ASL A           ; Put in b2-b3
         ASL A           ; Put in b3-b4
         ORA $E0         ; Add saved info
         STA $1850,Y     ; Put in SRAM area
C369A2:  DEX             ; Member slot -1
         BPL C3698C      ; Loop till last
         RTS

; Memorize current party (useless)
C369A9:; REP #$20        ; 16-bit A
       ; LDA $69         ; Members 1 and 2
       ; STA $7EAA89     ; Memorize them
       ; LDA $6B         ; Members 3 and 4
       ; STA $7EAA8B     ; Memorize them
       ; SEP #$20        ; 8-bit A
       ; RTS

; Draw multiple strings using consecutive pointers
C369BA:  PHA             ; Save counter
         PHX             ; Save index
         REP #$20        ; 16-bit A
         LDA.L C30000,X  ; Text pointer
         TAY             ; Set src LBs
         JSR C302F9      ; Draw string
         PLX             ; String index
         INX             ; Index +1
         INX             ; Index +1
         PLA             ; Strings left
         DEC A           ; One less left
         BNE C369BA      ; Loop till last
         RTS

; Set Window 1 positions per scanline
C369DC:  LDA #$01        ; 2Rx1B to PPU
         STA $4320       ; Set CH2 mode
         LDA #$26        ; $2126, $2127
         STA $4321       ; To Win 1 L+R
         LDY #C369FB     ; C3/69FB
         STY $4322       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4324       ; Set src HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Window 1 positions per scanline
C369FB:  db $07,$FF,$00  ; No range
         db $78,$08,$F7  ; 8, 247
         db $58,$08,$F7  ; 8, 247
         db $08,$FF,$00  ; No range
         db $00          ; End

; Set global Window 1 positions
C36A08:  LDA #$04        ; Channel: 2
         TRB $43         ; Halt Win1 HDMA
         LDX #$FF00      ; Win1-L: 0
         STX $2126       ; Win1-R: 255
         RTS

; Clear BG1 tilemap A
C36A15:  LDX #$3849      ; 7E/3849
         BRA C36A4E      ; Clear map

; Clear BG1 tilemap B
C36A19:  LDX #$4049      ; 7E/4049
         BRA C36A4E      ; Clear map

; Clear BG1 tilemap C
C36A1E:  LDX #$4849      ; 7E/4849
         BRA C36A4E      ; Clear map

; Clear BG1 tilemap D
C36A23:  LDX #$5049      ; 7E/5049
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap A
C36A28:  LDX #$5849      ; 7E/5849
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap B
C36A2D:  LDX #$6049      ; 7E/6049
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap C
C36A32:  LDX #$6849      ; 7E/6849
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap D (unused)
C36A37:  LDX #$7049      ; 7E/7049
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap A
C36A3C:  LDX #$7849      ; 7E/7849
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap B
C36A41:  LDX #$8049      ; 7E/8049
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap C
C36A46:  LDX #$8849      ; 7E/8849
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap D
C36A4B:  LDX #$9049      ; 7E/9049
C36A4E:  LDY #$0800      ; Bytes: 2048
         JMP clr_ram     ; Clear map

; Load graphics, colors, enemy, and prize for Colosseum matchup
C36A66:  JSR C36B13      ; BG3 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/VS GFX
         JSR C36CC7      ; Actor colors
         JSR C36C84      ; Cursor/VS colors
         JSR C36CE9      ; Actor sprites
         JSR C3AF46      ; Prize/enemy data
         JMP C3B34B      ; Arena

; Load non-skin graphics and colors for menu
C36A87:  TDC             ; Clear A
         LDA $0200       ; Menu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C36A90,X)  ; Load data

; Jump table for the above
C36A90:  dw C36AE9       ; Main menu
         dw C36B04       ; Actor naming
         dw C36AE9       ; Load menu
         dw C36ACE       ; Shop
         dw C36AB0       ; Lineup
         dw C36AB0       ; Bogus...
         dw C36AA4       ; SwdTech naming
         dw C36AE9       ; Colosseum
         dw C36AB0       ; Final battle lineup

; Load graphics and colors for SwdTech naming menu (SFC)
C36AA4:  JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/arrow GFX
         JMP C36C84      ; Their colors

; Load graphics and colors for Lineup or final battle menu
C36AB0:  JSR C37010      ; Blank portrait
         JSR C36B13      ; BG3 font GFX
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/icon GFX
         JSR C36CC7      ; Actor colors
         JSR C36C84      ; Cursor/icon pals
         JMP C36CE9      ; Actor sprites

; Load graphics and colors for shop menu
C36ACE:  JSR C36B13      ; BG3 font GFX
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/icon GFX
         JSR C36CC7      ; Actor colors
         JSR C36C84      ; Cursor/icon pals
         JMP C36D79      ; Actor sprites

; Load graphics and colors for Load, Main, or Colosseum menu
C36AE9:  JSR C36B13      ; BG3 font GFX
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/icon GFX
         JSR C36E82      ; Portrait GFX
         JSR C36C09      ; Portrait colors
         JSR C36CE9      ; Actor sprites
         JSR C36C84      ; Cursor/icon pals
         JMP C36C60      ; Grayscale pal

; Load graphics and colors for actor naming menu
C36B04:  JSR C36B13      ; Blank BG tile
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor GFX
         JMP C36C84      ; Cursor colors

; Upload BG3 font graphics and erase VWF description
C36B13:  REP #$20        ; 16-bit A
         LDY #$6000      ; $6000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C36B1D:  LDA $C47FC0,X   ; Font graphics
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1000      ; 256th tile?
         BNE C36B1D      ; Loop if not
C36B2B:  STA $2118       ; Clear desc GFX
         INX             ; Index +1
         CPX #$1400      ; 128th tile?
         BNE C36B2B      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload BG1 font graphics
C36B37:  LDY #$5000      ; $5000
         STY $2116       ; Set VRAM ptr
         REP #$20        ; 16-bit A
         TDC             ; Clear A
         TAX             ; Index: 0
C36B41:  LDY #$0008      ; 8-px rows: 8
C36B44:  LDA.L C36B9C,X  ; Square GFX
         STA $2118       ; Save in VRAM
         DEY             ; One less row
         BNE C36B44      ; Loop till last
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 8 tiles?
         BNE C36B41      ; Loop if not
         LDX $00         ; Index: 0
C36B57:  LDY #$0008      ; 8-px rows: 8
C36B5A:  LDA $C48040,X   ; Font GFX row
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less row
         BNE C36B5A      ; Loop till last
         LDY #$0008      ; 8-px rows: 8
.loop    STZ $2118       ; Planes C and D
         DEY             ; One less row
         BNE .loop       ; Loop till last
         CPX #$0F80      ; 248th tile?
         BNE C36B57      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Square BG1 tiles, encoded as a single row
C36B9C:  dw $0000,$0000  ; Blank tile
         dw $00FF,$0000  ; Config: Palette color 1
         dw $FF00,$0000  ; Config: Palette color 2
         dw $FFFF,$0000  ; Config: Palette color 3
         dw $0000,$00FF  ; Config: Palette color 4
         dw $00FF,$00FF  ; Config: Palette color 5
         dw $FF00,$00FF  ; Config: Palette color 6
         dw $FFFF,$00FF  ; Config: Palette color 7

; Reset all skin colors
C36BBC:  LDX #$0008      ; Skins left: 8
         STX $E7         ; Set counter
         LDX $00         ; ROM index: 0
         TXY             ; RAM index: 0
         REP #$20        ; 16-bit A
C36BC7:  LDA #$0007      ; Colors left: 7
         STA $E9         ; Set counter
C36BCC:  LDA $ED1C02,X   ; Default color
         STA $1D57,Y     ; Save in options
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E9         ; One less color
         BNE C36BCC      ; Loop till last
         TXA             ; ROM index
         CLC             ; Prepare ADC
         ADC #$0012      ; Reach next skin
         TAX             ; Reindex it
         DEC $E7         ; One less skin
         BNE C36BC7      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load font and black background's colors
C36BE8:  STZ $2121       ; To BG color 0
         LDX $00         ; Color index: 0
C36BEE:  REP #$20        ; 16-bit A
         LDA $D8E800,X   ; BG color
         STA $7E3049,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$00A0      ; Done 80 colors?
         BNE C36BEE      ; Loop if not
         RTS

; Load portrait colors for entire party
C36C09:  LDX $00         ; Member index: 0
         TXY             ; Dest index: 0
C36C0C:  PHX             ; Save member index
         PHY             ; Save dest index
         LDY $6D,X       ; Actor data index
         TDC             ; Clear A
         LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C36C25      ; Branch if not
         LDA #$0F        ; Use Imp data
         BRA C36C30      ; Ignore actor
C36C25:  LDA $0000,Y     ; Actor
         CMP #$01        ; Locke?
         BEQ C36C30      ; Branch if so
         LDA $0001,Y     ; Graphics set
C36C30:  TAX             ; Index it
         LDA.L C36F00,X  ; Palette number
         JSR x32r        ; x32
         TAX             ; Index it
         PLY             ; RAM index
         JSR C367A5      ; Load palette
         PLX             ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C36C0C      ; Loop if not
         RTS

; Load grayscale actor palette
C36C60:  LDA #$90        ; Object color 16
         STA $2121       ; CGRAM: $0120
         LDX $00         ; Color index: 0
C36C67:  REP #$20        ; 16-bit A
         LDA $D8E8A0,X   ; Grayscale color
         STA $7E3169,X   ; To OBJ pal 1
         JSR cgram       ; Save in CGRAM
         CPX #$0020      ; Done 16 colors?
         BNE C36C67      ; Loop if not
         RTS

; Load cursor, arrow, and icon colors
C36C84:  LDX $00         ; Color index: 0
         LDA #$EC        ; Object color 108
         STA $2121       ; CGRAM: $01D8
C36C8B:  REP #$20        ; 16-bit A
         LDA $D8E8C0,X   ; Status icon color
         STA $7E3221,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$0008      ; Done 4 colors?
         BNE C36C8B      ; Loop if not
         LDX $00         ; Color index: 0
         LDA #$FC        ; Object color 124
         STA $2121       ; CGRAM: $01F8
C36CAC:  REP #$20        ; 16-bit A
         LDA $D8E8B8,X   ; Cursor, etc. color
         STA $7E3241,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$0008      ; Done 4 colors?
         BNE C36CAC      ; Loop if not
         RTS

; Load actor sprite palettes
C36CC7:  LDA #$A0        ; Object color 32
         STA $2121       ; CGRAM: $0140
         LDX $00         ; Color index: 0
C36CCE:  REP #$20        ; 16-bit A
         LDA $ED6300,X   ; Sprite color
         STA $7E3189,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$00C0      ; Done 96 colors?
         BNE C36CCE      ; Loop if not
         RTS

; Upload actor sprite graphics (one pose)
C36CE9:  TDC             ; Clear A
         TAX             ; OBJ index: 0
C36CEB:  PHX             ; Save index
         REP #$20        ; 16-bit A
         LDA $CFF8E5,X   ; VRAM pointer
         STA $F3         ; Memorize it
         TXA             ; Sprite index
         ASL A           ; Double it
         TAX             ; Index it
         LDA $CFF913,X   ; GFX adr LBs
         STA $E7         ; Memorize it
         LDA $CFF911,X   ; GFX adr HBs
         STA $E9         ; Memorize it
         LDX $00         ; Ptr index: 0

; Fork: Head and torso
C36D05:  LDA $CFF8DF,X   ; Tile rel ptr
;        STA $EF         ; Memorize it
         JSR C36D44      ; Load 2 tiles
         INC $F4         ; VRAM: +1 row
         INX             ; Ptr index +1
         INX             ; Ptr index +1
         CPX #$0004      ; Done 2 rows?
         BNE C36D05      ; Loop if not

; Fork: Legs
C36D1D:  LDA $F3         ; VRAM pointer
         SEC             ; Prepare SBC
         SBC #$01E0      ; Row -2, col +2
         STA $F3         ; Save changes
         LDA $CFF8DF,X   ; Tile rel ptr
;        STA $EF         ; Memorize it
         JSR C36D44      ; Load leg GFX

; Fork: Blank row
C36D2E:  INC $F4         ; VRAM: +1 row
         JSR C36D67      ; Blank 4th row

; Fork: Handle next sprite
C36D39:  PLX             ; Sprite index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$002C      ; 22th sprite?
         BNE C36CEB      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload both tiles in current row of actor sprite
C36D44:  CLC             ; Prepare ADC
;        LDA $EF         ; Tile rel pointer
         ADC $E7         ; Add base adr LBs
         STA $EB         ; Set src LBs
         TDC             ; Zero A
         ADC $E9         ; Add adr HBs + C
         STA $ED         ; Set source HBs
         LDY $F3         ; VRAM pointer
         STY $2116       ; Set destination
C36D58:  LDY $00         ; Index: 0
C36D5A:  LDA [$EB],Y     ; Tile graphics
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0040      ; Done 2 tiles?
         BNE C36D5A      ; Loop if not
         RTS

; Blank both tiles under actor's feet
C36D67:  LDY $F3         ; VRAM pointer
         STY $2116       ; Set destination
         LDA #$0020      ; Tiles: 2
         JMP C3B113      ; Create tiles

; Upload actor sprites for shop
C36D79:  LDY #$3000      ; $3000
         STY $2116       ; Set VRAM ptr
         STZ $E3         ; Actor slot: 1

; Fork: Load both poses for two actors
C36D81:  LDY $00         ; Tile slot: 1
C36D83:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         TYX             ; Tile slot
         LDA.L C36E07,X  ; GFX ptr index
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36E27,X  ; Tile's GFX ptr
         CMP #$FFFF      ; Blank tile?
         BEQ C36DEA      ; Blank if so
         PHY             ; Save tile slot
         PHA             ; Save pointer
         SEP #$20        ; 8-bit A
         LDA $E3         ; Actor A's slot
         LDY #$16A0      ; GFX struct size
         JSR mul16       ; Slot x size
         REP #$21        ; 16-bit A; C-
         PLA             ; Tile GFX ptr
         ADC $2134       ; Add product LBs
         STA $EB         ; Set source LBs
         SEP #$20        ; 8-bit A
         LDA $2136       ; Product HB
         ADC #$D5        ; Add base bank
         STA $ED         ; Set source HB
         REP #$20        ; 16-bit A
         JSR C36DF8      ; Load tile's GFX
         PLY             ; Tile slot
C36DD7:  INY             ; Tile slot +1
         CPY #$0020      ; Done 32 tiles?
         BNE C36D83      ; Loop if not

; Fork: Handle next two actors
C36DDD:  SEP #$20        ; 8-bit A
         INC $E3         ; Actor slot +1
         INC $E3         ; Actor slot +1
         LDA $E3         ; Actor slot
         CMP #$10        ; Handled 16?
         BNE C36D81      ; Loop if not
         RTS

; Fork: Create a blank tile
C36DEA:  JSR C3B10A      ; Create tile
         BRA C36DD7      ; Do next tile

; Upload current actor sprite tile for shop
C36DF8:  LDY $00         ; Index: 0
C36DFA:  LDA [$EB],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0020      ; Done 8 rows?
         BNE C36DFA      ; Loop if not
         RTS

; Indices for loading tiles from two shop actors
C36E07:  db $00          ; Actor1 X1,Y1 (hands down)
         db $01          ; Actor1 X1,Y2 (hands down)
         db $04          ; Actor1 X3,Y1 (hands down)
         db $05          ; Actor1 X3,Y2 (hands down)
         db $08          ; Actor1 X1,Y1 (hands up)
         db $09          ; Actor1 X1,Y2 (hands up)
         db $0C          ; Actor1 X3,Y1 (hands up)
         db $0D          ; Actor1 X3,Y2 (hands up)
         db $10          ; Actor2 X1,Y1 (hands down)
         db $11          ; Actor2 X1,Y2 (hands down)
         db $14          ; Actor2 X3,Y1 (hands down)
         db $15          ; Actor2 X3,Y2 (hands down)
         db $18          ; Actor2 X1,Y1 (hands up)
         db $19          ; Actor2 X1,Y2 (hands up)
         db $1C          ; Actor2 X3,Y1 (hands up)
         db $1D          ; Actor2 X3,Y2 (hands up)
         db $02          ; Actor1 X2,Y1 (hands down)
         db $03          ; Actor1 X2,Y2 (hands down)
         db $06          ; Actor1 X4,Y1 (hands down)
         db $07          ; Actor1 X4,Y2 (hands down)
         db $0A          ; Actor1 X2,Y1 (hands up)
         db $0B          ; Actor1 X2,Y2 (hands up)
         db $0E          ; Actor1 X4,Y1 (hands up)
         db $0F          ; Actor1 X4,Y2 (hands up)
         db $12          ; Actor2 X2,Y1 (hands down)
         db $13          ; Actor2 X2,Y2 (hands down)
         db $16          ; Actor2 X4,Y1 (hands down)
         db $17          ; Actor2 X4,Y2 (hands down)
         db $1A          ; Actor2 X2,Y1 (hands up)
         db $1B          ; Actor2 X2,Y2 (hands up)
         db $1E          ; Actor2 X4,Y1 (hands up)
         db $1F          ; Actor2 X4,Y2 (hands up)

; Tile graphics pointers for odd-numbered shop actors
C36E27:  dw $03C0        ; 1,1 (hands down)
         dw $03E0        ; 1,2 (hands down)
         dw $0500        ; 2,1 (hands down)
         dw $0520        ; 2,2 (hands down)
         dw $0540        ; 3,1 (hands down)
         dw $0560        ; 3,2 (hands down)
         dw $FFFF        ; 4,1 (hands down)
         dw $FFFF        ; 4,2 (hands down)
         dw $03C0        ; 1,1 (hands up)
         dw $0660        ; 1,2 (hands up)
         dw $0680        ; 2,1 (hands up)
         dw $06A0        ; 2,2 (hands up)
         dw $06C0        ; 3,1 (hands up)
         dw $06E0        ; 3,2 (hands up)
         dw $FFFF        ; 4,1 (hands up)
         dw $FFFF        ; 4,2 (hands up)

; Tile graphics pointers for even-numbered shop actors
         dw $1A60        ; 1,1 (hands down)
         dw $1A80        ; 1,2 (hands down)
         dw $1BA0        ; 2,1 (hands down)
         dw $1BC0        ; 2,2 (hands down)
         dw $1BE0        ; 3,1 (hands down)
         dw $1C00        ; 3,2 (hands down)
         dw $FFFF        ; 4,1 (hands down)
         dw $FFFF        ; 4,2 (hands down)
         dw $1A60        ; 1,1 (hands up)
         dw $1D00        ; 1,2 (hands up)
         dw $1D20        ; 2,1 (hands up)
         dw $1D40        ; 2,2 (hands up)
         dw $1D60        ; 3,1 (hands up)
         dw $1D80        ; 3,2 (hands up)
         dw $FFFF        ; 4,1 (hands up)
         dw $FFFF        ; 4,2 (hands up)

; Upload cursor, arrow, and icon graphics (plus excess data)
C36E67:  REP #$20        ; 16-bit A
         LDY #$2000      ; $2000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C36E71:  LDA $ED5AC0,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1400      ; At ED/6EC0?
         BNE C36E71      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload each member's portrait
C36E82:  LDX $00         ; 1st: Member 1
C36E84:  REP #$20        ; 16-bit A
         LDA.L C36F51,X  ; VRAM pointer
         STA $2116       ; Set destination
         PHX             ; Save mbr index
         LDY $6D,X       ; Actor's address
         JSR faceptr     ; GFX pointer
         TAX             ; Index it
         JSR C37000      ; Upload portrait
         PLX             ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C36E84      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Set to upload healed member's portrait
C36EBF:  LDA #$ED        ; Bank: ED
         STA $1F         ; Set src HB
         LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $9C         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36F51,X  ; VRAM pointer
         STA $1B         ; Set destination
         LDY $6D,X       ; Actor's address
         JSR faceptr     ; GFX pointer
;        CLC             ; Prepare ADC
         ADC #$1D00      ; Add base adr
         STA $1D         ; Set src LBs
         SEP #$20        ; 8-bit A
         RTS

; Portrait palette assignments
C36F00:  db $00          ; 00: Terra
         db $01          ; 01: Locke
         db $02          ; 02: Cyan
         db $03          ; 03: Shadow
         db $04          ; 04: Edgar
         db $05          ; 05: Sabin
         db $06          ; 06: Celes
         db $07          ; 07: Strago
         db $08          ; 08: Relm
         db $09          ; 09: Setzer
         db $0A          ; 0A: Moogle
         db $0B          ; 0B: Gau
         db $0C          ; 0C: Gogo
         db $0D          ; 0D: Umaro
         db $0E          ; 0E: Soldier
         db $0F          ; 0F: Imp
         db $10          ; 10: Leo
         db $11          ; 11: Banon
         db $00          ; 12: Terra (unused; esper Terra)
         db $0E          ; 13: Soldier (unused; merchant)
         db $12          ; 14: Ghost
;        db $00          ; 15: Terra (unused; Kefka)
;        db $00          ; 16: Terra (unused; Gestahl)
;        db $00          ; 17: Terra (unused; Gungho)
;        db $00          ; 18: Terra (unused; Duane)
;        db $00          ; 19: Terra (unused; dog)
;        db $06          ; 1A: Celes (unused; Maria)

; Pointers to portrait graphics
C36F1B:  dw $0000        ; 00: Terra
         dw $0320        ; 01: Locke
         dw $0640        ; 02: Cyan
         dw $0960        ; 03: Shadow
         dw $0C80        ; 04: Edgar
         dw $0FA0        ; 05: Sabin
         dw $12C0        ; 06: Celes
         dw $15E0        ; 07: Strago
         dw $1900        ; 08: Relm
         dw $1C20        ; 09: Setzer
         dw $1F40        ; 0A: Mog
         dw $2260        ; 0B: Gau
         dw $2580        ; 0C: Gogo
         dw $28A0        ; 0D: Umaro
         dw $2BC0        ; 0E: Soldier
         dw $2EE0        ; 0F: Imp
         dw $3200        ; 10: Leo
         dw $3520        ; 11: Banon
         dw $0000        ; 12: Terra (unused; esper Terra)
         dw $2BC0        ; 13: Soldier (unused; merchant)
         dw $3840        ; 14: Ghost
;        dw $0000        ; 15: Terra (unused; Kefka)
;        dw $0000        ; 16: Terra (unused; Gestahl)
;        dw $0000        ; 17: Terra (unused; Gungho)
;        dw $0000        ; 18: Terra (unused; Duane)
;        dw $0000        ; 19: Terra (unused; dog)
;        dw $12C0        ; 1A: Celes (unused; Maria)

; VRAM pointers for portrait graphics
C36F51:  dw $2600        ; Member 1
         dw $2800        ; Member 2
         dw $2A00        ; Member 3
         dw $2C00        ; Member 4
;        dw $2E00        ; Bogus...
;        dw $3000        ; Bogus...
;        dw $3200        ; Bogus...
;        dw $3400        ; Bogus...

; List actor sprites for save file 1
C36F61:  LDY $91         ; File checksum
         LDX #$AA71      ; List address
         BRA C36FD_      ; Build list

; List actor sprites for save file 2
C36FB8:  LDY $93         ; File checksum
         LDX #$AA75      ; List address
         BRA C36FD_      ; Build list

; List actor sprites for save file 3
C36FDC:  LDY $95         ; File checksum
         LDX #$AA79      ; List address
C36FD_:  STX $2181       ; Set WRAM LBs
         CPY $00         ; Blank file?
         BEQ C36FFB      ; Nobody if so
         LDX $00         ; Member slot: 1
C36FE2:  LDA $69,X       ; Actor in slot
         BMI C36FEE      ; Blank if none
         JSR C36F97      ; Get sprite set
         JSR C36FA6      ; Handle soldier
         BRA C36FF0      ; Skip a line
C36FEE:  LDA #$FF        ; Sprite: None
C36FF0:  STA $2180       ; Set sprite
         INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C36FE2      ; Loop if not
         RTS

; Fork: Empty party
C36FFB:  LDX #$0004      ; Members: 4
         LDA #$FF        ; Sprite: None
.loop    STA $2180       ; Set member's
         DEX             ; One less left
         BPL .loop       ; Loop till last
         RTS

; Get actor's graphics set
C36F97:  PHX             ; Save X
         REP #$20        ; 16-bit A
         TXA             ; Actor number
         JSR C32D0_      ; Define Y
         SEP #$20        ; 8-bit A
         PLX             ; Restore X
         LDA $0001,Y     ; Graphics set
         RTS

; Choose between green or brown soldier
C36FA6:  CMP #$0E        ; Soldier sprite?
         BNE C36FB7      ; Exit if not
         LDA $1EA0       ; Event flags
         BIT #$08        ; Soldier disguise?
         BEQ C36FB5      ; Pick brown if not
         LDA #$16        ; Use green soldier
         RTS             ; Exit
C36FB5:  LDA #$0E        ; Use brown soldier
C36FB7:  RTS

; Upload actor's portrait graphics
C37000:  LDY #$0190      ; Tiles: 25
C37003:  LDA $ED1D00,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less word
         BNE C37003      ; Loop till last
         RTS

; Create a blank portrait for Lineup menu
C37010:  LDX #$9F51      ; 7E/9F51
         LDY #$0320      ; Tiles: 25
         JMP clr_ram     ; Clear data

; Validate SRAM markers
C37023:  PHB             ; Save DB
         LDA #$30        ; Bank: 30
         PHA             ; Put on stack
         PLB             ; Set DB to 30
         LDX #$E41B      ; Square's marker
         CPX $7FF8       ; In file A?
         BEQ C37047      ; Okay if so
         CPX $7FFA       ; In file B?
         BEQ C37047      ; Okay if so
         CPX $7FFC       ; In file C?
         BEQ C37047      ; Okay if so
         CPX $7FFE       ; In file D?...
         BNE C3704B      ; Delete if not
C37047:  PLB             ; Restore DB
         SEC             ; Call Load menu
         RTS

; Fork: Delete all saved data
C3704B:  REP #$20        ; 16-bit A
         LDX $00         ; SRAM index: 0
C37055:  STZ $6000,X     ; Clear SRAM word
         INX             ; Index +1
         INX             ; Index +1
         CPX #$2000      ; Fully cleared?
         BNE C37055      ; Loop if not
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         CLC             ; Skip Load menu
         RTS

; Reset saved cursor positions for main menu
C37068:  JSR C348F7      ; Clear positions
         LDA #$01        ; Skills: "Magic"
         STA $0237       ; Set for ally 1
         STA $0239       ; Set for ally 2
         STA $023B       ; Set for ally 3
         STA $023D       ; Set for ally 4
         RTS

; Mark all save files as Square's property
C37083:  REP #$20        ; 16-bit A
         LDA #$E41B      ; Square marker
         STA $307FF8     ; Mark file A
         STA $307FFA     ; Mark file B
         STA $307FFC     ; Mark file C
         STA $307FFE     ; No file D...
         SEP #$20        ; 8-bit A
         RTS

; Reset game data for Load menu
C3709B:  JSR C37068      ; Clear cursor mem
         LDY #$7FFF      ; Color: White
         STY $1D55       ; Set user font's
         LDA #$12        ; Buttons: A & B
         STA $1D50       ; Define purpose
         LDA #$34        ; Buttons: X & Y
         STA $1D51       ; Define purpose
         LDA #$56        ; Buttons: L & R
         STA $1D52       ; Define purpose
         LDA #$06        ; Button: Select
         STA $1D53       ; Define purpose
         LDA #$2A        ; Bat.Mode, etc.
         STA $1D4D       ; Define options
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $1DC7       ; Save count: 0
         STZ $1D54       ; Mag.Order, etc.
         STZ $1D4E       ; Wallpaper, etc.
         STZ $1D4F       ; Pad assignments
         STY $1863       ; SRAM hours, mins
         STZ $1865       ; SRAM seconds
         STY $1860       ; Gold LBs
         STZ $1862       ; Gold HB
         STY $1866       ; Steps LBs
         STZ $1868       ; Steps HB
         STY $021B       ; Real hours, mins
         STY $021D       ; Real secs, frames
         JMP C36BBC      ; Reset skin colors

; 2C: Initialize Lineup menu
C370E7:  JSR C370FC      ; Init variables
         STZ $4A         ; Cursor area: Top
         JSR C3762A      ; List/Create actors
         JSR C37482      ; Load navig data
         JSR C3748B      ; Relocate cursor
         BRA C37114      ; Draw menu, etc.

; Initialize variables for Lineup menu
C370FC:  JSR C3352F      ; Reset/Stop stuff
         JSR C36904      ; Reset BGs' X/Y
;        LDA #$03        ; 64x64 at $0000
;        STA $2107       ; Set BG1 map loc
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDA #$06        ; Status icons: Temp
         TSB $47         ; Set menu flag
         RTS

; Draw Lineup menu, etc.
C37114:  JSR C307B0      ; Queue cursor OAM
         JSR C375C5      ; Set to shift text
         JSR C37522      ; Draw boxes/title
         JSR C3793F      ; Create portrait
         JSR C37953      ; Draw actor info
         JSR C30EFD      ; Queue text upload
         LDA #$2D        ; C3/7168
         STA $27         ; Queue: Choice 1
         LDA #$66        ; C3/79FF
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 7D: Return to Lineup menu from Status menu
C37131:  JSR C370FC      ; Init variables
         LDA #$20        ; Channel: 5
         TRB $43         ; Halt HDMA-5
         JSR C37677      ; Create/lock chars
         BRA C37114      ; Draw menu, etc.

; 2D: Handle Lineup menu choice 1
C37168:  JSR C371B9      ; Cover D-Pad/stats
         BCC C371DD      ; If crossed center
         LDA $08         ; Pushing A?
         BPL C371A9      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         LDA $7EAC8D,X   ; Locked slot?
         BMI C371A2      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $28         ; Set pick 1's
         LDA $4A         ; Cursor area
         STA $49         ; Set pick 1's
         LDA #$2E        ; C3/720C
         STA $26         ; Next: Choice 2
         JMP C32F21      ; Create blinker

; Fork: Forced member
C371A2:  JMP C3B66F      ; Buzzer + Mosaic

; Fork: Exit attempt
C371A9:  LDA $09         ; No-autofire keys
         BIT #$90        ; Using Start or B?
         BEQ C371DD      ; Exit if not
         JMP C37296      ; Validate groups

; Handle D-Pad and update actor info in Lineup menu
C371B9:  JSR C375B8      ; Update char info
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C371DE      ; Branch if not
         LDA $4E         ; On row 1 or 3?
         BEQ C371DE      ; Branch if so
         LDA $4A         ; In party area?
         BNE C371DE      ; Branch if so

; Fork: Enter party area
C371CC:  LDA #$10        ; Cursor slot: +16
         STA $4A         ; Set area mod
         JSR C373DB      ; Relocate cursor
         JSR C30EA3      ; Sound: Cursor
         CLC             ; Mark area exit
C371DD:  RTS

; Fork: Handle up
C371DE:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C37206      ; Branch if not
         LDA $4E         ; On row 1 or 3?
         BNE C37206      ; Branch if not
         LDA $4A         ; In party area?
         BEQ C37206      ; Branch if not

; Fork: Exit party area
C371EC:  LDA $4D         ; Cursor column
         STA $5E         ; Set as former
         STZ $4A         ; Cursor area: Top
         JSR C37482      ; Load navig data
         INC $4E         ; Cursor row: 2nd
         TDC             ; Clear A
         LDA $5E         ; Former column
         TAX             ; Index it
         LDA.L C37476,X  ; Intended column
         STA $4D         ; Set new column
         JSR C3748B      ; Relocate cursor
         JSR C30EA3      ; Sound: Cursor
         CLC             ; Mark area exit
         RTS

; Fork: Staying within same area
C37206:  JSR C37415      ; Handle D-Pad
         SEC             ; Unmark area exit
C3720B:  RTS

; 2E: Handle Lineup menu choice 2
C3720C:  JSR C371B9      ; Cover D-Pad/stats
         BCC C3720B      ; If crossed center
         LDA $08         ; Pushing A?
         BPL C3727D      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot B
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         STA $E0         ; Memorize sum
         TAX             ; Index it
         LDA $7EAC8D,X   ; Locked slot?
         BMI C3728F      ; Fail if so
         TDC             ; Clear A
         LDA $28         ; Cursor slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         CMP $E0         ; Slots are same?
         BNE C37265      ; Swap chars if not

; Fork: Double-clicked a slot
C37234:  LDA $E0         ; Chosen slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Empty slot?
         BMI C37277      ; Fail if so
         LDA #$42        ; C3/631D
         STA $27         ; Queue Status menu
         LDA #$67        ; C3/79F0
         STA $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Fork: Swap slot contents
C37265:  JSR C30EB2      ; Sound: Click
         LDA #$07        ; Actors: Delete
         TRB $47         ; Set menu flag
         JSR C372F8      ; Swap positions
         JSR C311B0      ; Delete actors
         JSR C37613      ; Create actors
         BRA C37286      ; Next: Choice 1

; Fork: Double-clicked empty slot
C37277:  JSR C3B66F      ; Buzzer + Mosaic

; Fork: Handle B
C3727D:  LDA $09         ; Pushing B?
         BPL C3728E      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C37286:  LDA #$2D        ; C3/7168
         STA $26         ; Next: Choice 1
         LDA #$05        ; Blinker: Off
         TRB $46         ; Set menu flag
C3728E:  RTS

; Fork: Forced member
C3728F:  JMP C3B66F      ; Buzzer + Mosaic

; Handle attempt to exit Lineup menu
C37296:  LDA $0201       ; Group count
;        AND #$7F        ; Clear flag
         ASL A           ; x2
         ASL A           ; x4 members
         STA $F3         ; Set index cap
         STZ $F4         ; Clear its HB
         TDC             ; Clear A
         TAX             ; Slot index: 0
C372A3:  STZ $E0         ; Members: 0
         LDY #$0004      ; Slots left: 4
C372A8:  LDA $7E9D99,X   ; Empty slot?
         BMI C372B0      ; Branch if so
         INC $E0         ; +1 member
C372B0:  INX             ; Slot index +1
         DEY             ; One less slot
         BNE C372A8      ; Loop till 4th
         LDA $E0         ; Empty party?
         BEQ C372CB      ; Fail if so
         CPX $F3         ; Last party?
         BNE C372A3      ; Loop if not
;        STZ $0205       ; Never read...
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         LDA #$67        ; C3/79F0
         STA $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Draw "You need <#> group(s)."
C372CB:  JSR C30EC0      ; Play buzzer
         JSR C3C2F2      ; Color: User's
         LDA $0201       ; Event data
         AND #$07        ; Group count
         DEC A           ; One group?
         BEQ C372E9      ; Branch if so
         LDY #C37AB7     ; Text pointer
         JSR C302F9      ; Draw message
         LDX #$392F      ; Tilemap pointer
         JSR C375F7      ; Draw group count
         BRA C372EF      ; Skip 2 lines

; Fork: Draw "No one there!"
C372E9:  LDY #C37ACE     ; Text pointer
         JSR C302F9      ; Draw message
C372EF:  LDA #$20        ; Frames: 32
         STA $20         ; Set wait timer
         LDA #$69        ; C3/7A87
         STA $26         ; Next: Wait
         RTS

; Swap actor positions in Lineup menu
C372F8:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         TAX             ; Index sum
         PHX             ; Memorize it
         LDA $7E9D89,X   ; Actor in slot A
         STA $E0         ; Memorize it
         LDA.L C373AF,X  ; Party position
         STA $E3         ; Memorize it

; Fork: Get actor data for slot B
C37326:  LDA $4B         ; Chosen slot B
         CLC             ; ...
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         PHX             ; Memorize it
         LDA $7E9D89,X   ; Actor in slot B
         STA $E1         ; Memorize it
         LDA.L C373AF,X  ; Party position
         STA $E2         ; Memorize it

; Fork: Update party info for both actors
C37361:  LDX #$0001      ; 1st: Actor B
.loop    LDA $E0,X       ; Actor in slot
         BMI .next       ; Skip if none
         TAY             ; Index it
         LDA $1850,Y     ; Actor info
         AND #$20        ; Isolate row
         ORA $E2,X       ; Add new position
         STA $1850,Y     ; Save changes
.next    DEX             ; Actor index -1
         BPL .loop       ; Loop till < 0

; Fork: Swap slot contents
C37391:  PLX             ; Menu slot B
         LDA $E0         ; Actor in slot A
         JSR .recur      ; Put in slot B
         PLX             ; Menu slot A
         LDA $E1         ; Actor in slot B
.recur   STA $7E9D89,X   ; Put in slot A
         RTS

; Party and roster position for Lineup menu slots
C373AF:  db $40          ; Non-party slot 1
         db $40          ; Non-party slot 2
         db $40          ; Non-party slot 3
         db $40          ; Non-party slot 4
         db $40          ; Non-party slot 5
         db $40          ; Non-party slot 6
         db $40          ; Non-party slot 7
         db $40          ; Non-party slot 8
         db $40          ; Non-party slot 9
         db $40          ; Non-party slot 10
         db $40          ; Non-party slot 11
         db $40          ; Non-party slot 12
         db $40          ; Non-party slot 13
         db $40          ; Non-party slot 14
         db $40          ; Non-party slot 15
         db $40          ; Non-party slot 16
         db $41          ; Party 1, NW
         db $49          ; Party 1, SW
         db $51          ; Party 1, NE
         db $59          ; Party 1, SE
         db $42          ; Party 2, NW
         db $4A          ; Party 2, SW
         db $52          ; Party 2, NE
         db $5A          ; Party 2, SE
         db $43          ; Party 3, NW
         db $4B          ; Party 3, SW
         db $53          ; Party 3, NE
         db $5B          ; Party 3, SE

; New cursor column upon entering 3-party area of Lineup menu
C37466:  db $00          ; 1 -> 1
         db $01          ; 2 -> 2
         db $01          ; 3 -> 2
         db $02          ; 4 -> 3
         db $03          ; 5 -> 4
         db $04          ; 6 -> 5
         db $04          ; 7 -> 5
         db $05          ; 8 -> 6

; New cursor column upon leaving 3-party area of Lineup menu
C37476:  db $00          ; 1 -> 1
         db $01          ; 2 -> 2
         db $03          ; 3 -> 4
         db $04          ; 4 -> 5
         db $06          ; 5 -> 7
         db $07          ; 6 -> 8

; Load nav data for party area of Lineup menu, relocate cursor
C373DB:  LDA $4D         ; Cursor column
         STA $5E         ; Set as former
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         DEC A           ; One group?
         BEQ C373F5      ; Branch if so
         DEC A           ; Two groups?
         BEQ C37405      ; Branch if so

; Fork: Three groups
C373EC:  LDY #C37505     ; C3/7505
         JSR C305FE      ; Load navig data
         TDC             ; Clear A
         LDA $5E         ; Former column
         TAX             ; Index it
         LDA.L C37466,X  ; Intended column
         STA $4D         ; Set new column
         JMP C374B8      ; Relocate cursor

; Fork: One group
C373F5:  LDY #C374E3     ; C3/74E3
         JSR C305FE      ; Load navig data
         LDA $5E         ; Old cursor column
         BEQ C37400      ; Retain if first
         LDA #$01        ; Column: 2nd
C37400:  STA $4D         ; Set new column
         BRA C3749A      ; Relocate cursor

; Fork: Two groups
C37405:  LDY #C374F0     ; C3/74F0
         JSR C305FE      ; Load navig data
         LDA $5E         ; Old cursor column
         CMP #$03        ; Within first 3?
         BCC C37410      ; Retain it if so
         LDA #$03        ; Column: 4th
C37410:  STA $4D         ; Set new column
         JMP C374A9      ; Relocate cursor

; Handle D-Pad for Lineup menu
C37415:  LDA $4A         ; In party area?
         BEQ C37488      ; Branch if not
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         DEC A           ; One group?
         BEQ C37497      ; Branch if so
         DEC A           ; Two groups?
         BEQ C374A6      ; Branch if so
         BRA C374B5      ; Handle D-Pad

; Load navigation data for non-party area of Lineup menu
C37482:  LDY #C374BE     ; C3/74BE
         JMP C305FE      ; Load navig data

; Handle D-Pad for non-party area of Lineup menu
C37488:  JSR C3072D      ; Handle D-Pad
C3748B:  LDY #C374C3     ; C3/74C3
         JMP C30640      ; Relocate cursor

; Handle D-Pad for single-party area of Lineup menu
C37497:  JSR C3072D      ; Handle D-Pad
C3749A:  LDY #C374E8     ; C3/74E8
         JMP C30637      ; Relocate cursor

; Handle D-Pad for two-party area of Lineup menu
C374A6:  JSR C3072D      ; Handle D-Pad
C374A9:  LDY #C374F5     ; C3/74F5
         JMP C30637      ; Relocate cursor

; Handle D-Pad for three-party area of Lineup menu
C374B5:  JSR C3072D      ; Handle D-Pad
C374B8:  LDY #C3750A     ; C3/750A
         JMP C30637      ; Relocate cursor

; Draw Lineup menu windows and uppermost text
C37522:  LDX #C37598     ; C3/7598
         JSR boxes       ; Draw main boxes
         JSR C37572      ; Draw party boxes
         JSR C30E52      ; Upload windows
         JSR C36A3C      ; Clear BG3 map A
         JSR C30E6E      ; Upload BG3 A+B
         JSR C36A15      ; Clear BG1 map A
         JSR C35F34      ; Color: Blue
         LDY #C37AAE     ; Text pointer
         JSR C302F9      ; Draw "Lineup"
         JSR C37562      ; Draw "Form..."
         JMP C30E28      ; Upload BG1 A+B

; Draw "Form <#> group(s)."
C37562:  JSR C3C2F2      ; Color: User's
         LDY #C37A95     ; Text pointer
         JSR C302F9      ; Draw "Form..."
         LDX #$3927      ; Tilemap pointer
         BRA C375F7      ; Draw group count

; Draw extra party boxes for Lineup menu
C37572:  TDC             ; Clear A
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         DEC A           ; One group?
         BEQ C375F6      ; Exit if so
         LDX #C375B4     ; C3/75B4
         DEC A           ; 2 parties?
         BEQ .draw       ; 1 box if so
         LDX #C375B0     ; C3/75B0
.draw    JMP boxes       ; Draw box(es)

; Update displayed actor info in Lineup menu
C375B8:  LDA #$06        ; Status icons: Temp
         TSB $47         ; Set menu flag
         JSR C37C2F      ; Queue face upload
         JSR C37CAE      ; Load face colors
         JMP C37953      ; Draw actor info

; Set to condense text in Lineup menu
C375C5:  LDY #C375E4     ; Source LBs
         LDA #$C3        ; Source HB
         JMP bg1v        ; Queue BG1 V-Pan
C375F6:  RTS

; Draw number of required groups for Lineup menu
C375F7:  LDA $0201       ; Event data
         AND #$07        ; Group count
         DEC A           ; Now 0-6
         JMP C34116      ; Draw value

; List members and create actors after changes in Lineup menu
C37613:  LDX #$008F      ; Starting slot
         LDA #$FF        ; Actor: None
C37617:  STA $7E9D99,X   ; Clear slot
         DEX             ; Slot number -1
         BPL C37617      ; Loop till < 0
         JSR C376EA      ; Compile members
         JSR C37853      ; Create members
         BRA C37683      ; And candidates

; List and create actors in Lineup menu, define locked slots
C3762A:  LDX #$009F      ; Starting slot
         LDA #$FF        ; Actor: None
C3762E:  STA $7E9D89,X   ; Clear slot
         DEX             ; Slot number -1
         BPL C3762E      ; Loop till < 0
         JSR wm9D89      ; WRAM: 7E/9D89
         LDA $0201       ; Forced members?
         BMI C37665      ; Branch if not

; Fork: Compile candidates, etc.
C37643:  LDX $00         ; 1st: Terra
C37645:  LDA $1850,X     ; Party info
         ASL A           ; Object's off?
         BPL C37657      ; Skip if so
         AND #$0E        ; In a party?
         BNE C37657      ; Skip if so
         TXA             ; Actor's slot
         STA $2180       ; Add to list
C37657:  INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C37645      ; Loop if not
         LDA #$FF        ; Null value
         STA $2180       ; End list
         BRA C37677      ; Make/lock chars

; Fork: Clear assigned party for all actors
C37665:  LDX #$000F      ; 1st: Guest 2
C37667:  LDA $1850,X     ; Party info
         AND #$F8        ; Clear party
         STA $1850,X     ; Save changes
         DEX             ; Actor slot -1
         BPL C37667      ; Loop till last
         BRA C37643      ; Create actors

; List members, create actors, and define locked slots in Lineup menu
C37677:  JSR C376EA      ; Compile members
         JSR C37853      ; Create members
         JSR C37683      ; And candidates
         JMP C3790C      ; Set locked slots

; Create all candidates in Lineup menu
C37683:  LDX $00         ; Menu slot: 1
C37685:  LDA $7E9D89,X   ; Actor in slot
         BMI C376BF      ; Skip if none
         PHX             ; Save slot
         PHA             ; Save actor
         LDY #C37A5F     ; C3/7A5F
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         PLA             ; Actor
         STA $7E35C9,X   ; Save for arrow
         JSR C378EB      ; Set anim ptr
         PLX             ; Menu slot
         LDA.L C376CA,X  ; X position
         STA $33CA,Y     ; Set sprite's
         LDA.L C376DA,X  ; Y position
         STA $344A,Y     ; Set sprite's
C376BF:  INX             ; Menu slot +1
         CPX #$0010      ; Done top 16?
         BNE C37685      ; Loop if not
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Compile party members for Lineup menu
C376EA:  LDY #$000F      ; 1st: Guest 2
.loop    TDC             ; Clear A
         LDA $1850,Y     ; Party info
         PHA             ; Memorize it
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         STA $E0         ; Memorize it
         PLA             ; Party info
         ASL A           ; Object's off?
         BPL .next       ; Skip if so
         AND #$06        ; Isolate party
         BEQ .next       ; Skip if none
         ASL A           ; Party x4
         ORA $E0         ; Add roster slot
         TAX             ; Index sum
         TYA             ; Actor slot
         STA $7E9D99-4,X ; Add to list
.next    DEY             ; Actor slot -1
         BPL .loop       ; Loop till < 0
         RTS

; Create all party members in Lineup menu
C37853:  LDX #$9D99      ; 7E/9D99
         STX $F3         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $F5         ; Set src HB
         LDX $00         ; Menu slot: 1
C37881:  TXY             ; Menu slot
         LDA [$F3],Y     ; Actor in slot
         BMI C378C0      ; Skip if nobody
         PHX             ; Save slot
         PHA             ; Save actor
         LDY #C37B42     ; C3/7B42
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         PLA             ; Actor in slot
         STA $7E35C9,X   ; Put in queue
         JSR C378EB      ; Set anim ptr
         PLX             ; Menu slot
         LDA.L C378E3,X  ; X position
         STA $33CA,Y     ; Set ally's
         PHX             ; Save X
         TDC             ; Clear A
         TXA             ; Menu slot
         AND #$03        ; Member slot
         TAX             ; Reindex it
         LDA.L C378E7,X  ; Y position
         STA $344A,Y     ; Set ally's
         PLX             ; Menu slot
C378C0:  INX             ; Menu slot +1
         CPX #$000C      ; Done all 12?
         BNE C37881      ; Loop if not
         RTS

; Load pointer to actor's animation table
C378EB:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $01,X       ; Sprite set
C378FA:  ASL A           ; Double it
         TAX             ; Index it
         JSR db7e        ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $D8E917,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
         RTS

; Establish locked actor slots in Lineup menu
C3790C:  LDX #$002B      ; Menu slot: Last
C37914:  PHX             ; Save menu slot
         TDC             ; Clear A
         LDA $7E9D89,X   ; Actor in slot
         BMI C37933      ; Unlock if none
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C39C67,X  ; Actor slot bit
         AND $0202       ; Forced member?
         SEP #$20        ; 8-bit A
         BEQ C37933      ; Unlock if not
         LDA #$FF        ; Slot: Locked
         BRA C37934      ; Skip a line
C37933:  TDC             ; Slot: Unlocked
C37934:  PLX             ; Current slot
         STA $7EAC8D,X   ; Set slot status
         DEX             ; Menu slot -1
         BPL C37914      ; Loop till < 0
C3793E:  RTS

; Initialize and load portrait for Lineup menu
C3793F:  STZ $28         ; Portr slot: 1
         JSR C37AE5      ; Init object
         LDY #$2F1A      ; Pos: 26, 47
         JSR objpos      ; Set sprite's
         JSR C314AC      ; Upload graphics
         JSR C37C2F      ; Queue updating
         JMP C37CAE      ; Load palette

; Draw actor info in Lineup menu
C37953:  LDX #$3A09      ; Tilemap ptr
         LDY #$0180      ; Tiles: 192
         JSR clr_ram     ; Erase BG1 text
;        TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if in party
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BMI C3793E      ; Exit if nobody
         STA $C9         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         STA $67         ; Memorize it
         SEP #$20        ; 8-bit A
         JSR C35F34      ; Color: Blue
         LDX #C379C9     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3A5B      ; Class/KO pos
         LDX #$3048      ; Icon position
         LDA #$01        ; Anim mode: 1
         STA $48         ; Set for icons
         JSR C33427      ; Display status
         LDY #$3ADB      ; Text position
         JSR C334CF      ; Draw actor name
         LDY #$3B5B      ; Text position
         JSR C334E6      ; Draw held esper
         LDY #C379DE     ; Text pointer
         JSR C302F9      ; Draw HP's "/"
         LDY #C379E2     ; Text pointer
         JSR C302F9      ; Draw MP's "/"
         LDX #C379E6     ; Coords tbl ptr
         JMP C30C6C      ; Draw LV, HP, MP

; 67: Queue fade-out for Lineup menu
C379F0:  JSR C3304F      ; Queue fade-out
         BRA C37A02      ; Skip a line

; 66: Queue fade-in for Lineup menu
C379FF:  JSR C33056      ; Queue fade-in
C37A02:  LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$68        ; C3/7A0E
         STA $26         ; Next: Wait
         BRA C37A16      ; Update char info

; 68: Wait while Lineup menu fades in or out
C37A0E:  LDY $20         ; Timer expired?
         BNE C37A16      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C37A16:  JMP C375B8      ; Update char info

; Update arrow for gear data menu
C37A19:  BNE C37A3E      ; If mode 1

; Mode 0: Initialize arrow
C37A21:  LDA #$D8        ; Anim ptr HB
         LDY #$EC6F      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C37A3E:  TXY             ; Queue index
         LDX $00         ; Arrow: Blank
         LDA $99         ; Arrow status
         BEQ C37A4B      ; Hide if bogus
         BMI C37A85      ; Delete if off
         INX #2          ; Arrow: Normal
C37A4B:  REP #$20        ; 16-bit A
         LDA $D8EC6B,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue

; Update Lineup or Colosseum candidate, or enemy Shadow
C37A5F:  BNE C37A78      ; If mode 1

; Mode 0: Initialize sprite
C37A67:  LDA #$01        ; Hide actors: N
         TSB $47         ; Set menu flag
         JSR C3120_      ; Set pose timer
         INC $3649,X     ; Mode +1
;        JSR C37BAE      ; No arrow...

; Mode 1: Sustain sprite
C37A78:  LDA $47         ; Menu flags
         LSR A           ; Remove actors?
         BCC C37A85      ; Delete if so
         JMP oamsec      ; Set OAM; requeue
C37A85:  CLC             ; Set to dequeue
         RTS

; 69: Erase warning in Lineup menu after delay
C37A87:  LDA $20         ; Delay expired?
         BNE C37A92      ; Branch if not
         LDA #$2D        ; C3/7168
         STA $26         ; Next: Choice 1
         JSR C37562      ; Draw "Form..."
C37A92:  JMP C375B8      ; Update char info

; Create portrait for Lineup menu
C37AE5:  JSR C361DA      ; Queue OAM fn
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         LDA $28         ; Portrait slot
         ASL A           ; Double it
         JSR C30AC_      ; Load anim ptr
         PLB             ; Restore DB
C37B0D:  RTS

; Sort members by actual order rather than actor slot
C37B25:  TDC             ; Clear A
         LDA $7E9D89,X   ; Actor slot
         STA $E1         ; Memorize it
         BMI C37B0D      ; Exit if none
         PHX             ; List slot
         TAX             ; Actor slot
         LDA $1850,X     ; Party info
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         TAY             ; Index it
         LDA $E1         ; Actor slot
         STA [$E7],Y     ; To new list
         PLX             ; List slot
         INX             ; List slot +1
         BRA C37B25      ; Do next slot

; Update conditional actor-related sprite
C37B42:  TAX             ; Index mode
         JMP (C37B46,X)  ; Handle mode

; Jump table for the above
C37B46:  dw C37B52       ; Initialize sprite V1
         dw C37B66       ; Initialize sprite V2
         dw C37B7E       ; Sustain sprite V1
         dw C37B8D       ; Sustain sprite V2

; Mode 0: Init Lineup member, non-Lineup status icon, or arrow under actor; create arrow under forced member
C37B52:  LDA #$01        ; Ax like OBJs: N
         TSB $47         ; Set menu flag
         JSR C3120_      ; Set pose timer
         LDA #$02        ; Mode: 2
         STA $3649,X     ; Set sprite's
         TDC             ; Lineup member: Y
         JSR C37BAE      ; Add Lineup arrow

; Mode 3: Sustain Lineup member, non-Lineup status icon, or arrow under actor
C37B7E:  LDA $47         ; Menu flags
         LSR A           ; Ax like objects?
         BCS C37B9A      ; Branch if not
C37B8B:  CLC             ; Set to dequeue
         RTS

; Mode 1: Init Colosseum challenger or Lineup status icon
C37B66:  JSR C3120_      ; Set pose timer
         LDA #$03        ; Mode: 3
         STA $3649,X     ; Set sprite's

; Mode 4: Sustain Colosseum challenger or Lineup status icon
C37B8D:  LDA $47         ; Menu flags
         AND #$02        ; Temp sprite?
         BEQ C37B9A      ; Branch if not
         JSR C31221      ; Define OAM
         CLC             ; Set to dequeue
         RTS             ; Exit
C37B9A:  JMP oamsec      ; Set OAM; requeue

; Create large arrow under actor if forced into party
C37BAE:  STA $E6         ; Save pose timer
         LDA $0200       ; Menu number
         CMP #$04        ; Lineup menu?
         BNE C37C0E      ; Exit if not
         LDX $2D         ; Queue index
         TDC             ; Clear A
         LDA $35C9,X     ; Actor in slot
         BMI C37C0E      ; Exit if arrow
         ASL A           ; Double it
         REP #$20        ; 16-bit A
         TAX             ; Index it
         LDA.L C39C67,X  ; Actor slot bit
         AND $0202       ; Forced member?
         SEP #$20        ; 8-bit A
         BEQ C37C0E      ; Exit if not
         PHB             ; Save DB
         LDY #C37A5F     ; C3/7A5F
         LDA $E6         ; Party member?
         BNE C37BE2      ; Branch if not
         LDY #C37B42     ; C3/7B42
C37BE2:  JSR qanim3      ; Queue OAM fn
         LDA #$D8        ; Anim ptr HB
         LDY #$EBA9      ; Anim ptr LBs
         JSR anm_st      ; Set arrow's
         PLB             ; Restore DB
         LDA #$FF        ; Actor: None
         STA $35C9,X     ; For C3/7BBD
         LDY $374A,X     ; Actor's index
         LDA $33CA,Y     ; Actor's X
         STA $33CA,X     ; Set arrow's
         LDA $344A,Y     ; Actor's Y
         STA $344A,X     ; Set arrow's
C37C0E:  RTS

; Set to upload portrait for Lineup menu
C37C2F:  LDY #$2600      ; $2600
         STY $1B         ; Set VRAM ptr
         LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BMI C37CA4      ; Blank if none
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAY             ; Index it
         JSR faceptr     ; GFX pointer
;        CLC             ; Prepare ADC
         ADC #$1D00      ; Add base adr
         STA $1D         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$ED        ; Bank: ED
         STA $1F         ; Set src HB
         RTS

; Fork: Point to blank portrait
C37CA4:  LDY #$9F51      ; 7E/9F51
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         RTS

; Load portrait palette for Lineup menu
C37CAE:  LDY $00         ; Palette: 0
         PHY             ; Save dest
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BPL C37CD6      ; Branch if any
         TDC             ; Use Terra
C37CD6:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C37CF1      ; Branch if not
         LDA #$0F        ; Use Imp data
         BRA C37CF4      ; Skip a line
C37CF1:  LDA $0001,Y     ; Graphics set
C37CF4:  TAX             ; Index it
         LDA.L C36F00,X  ; Palette number
         JSR x32r        ; x32
         TAX             ; Index it
         PLY             ; RAM index
         JMP C367A5      ; Load palette

; Load navigation data for Item, Colosseum, or Sell menu
C37D1C:  LDY #C37D2B     ; C3/7D2B
         JMP C305FE      ; Load navig data

; Handle D-Pad for Item, Colosseum, or Sell menu
C37D22:  JSR C381C7      ; Handle D-Pad
C37D25:  LDY #C37D30     ; C3/7D30
         JMP C30648      ; Relocate cursor

; Handle D-Pad for rare item menu
C37D4A:  JSR C3072D      ; Handle D-Pad
C37D4D:  LDY #C37D58     ; C3/7D58
         JMP C30640      ; Relocate cursor

; Load navigation data for Item menu options
C37D80:  LDY #C37D98     ; C3/7D98
         JMP C305FE      ; Load navig data

; Relocate cursor for Item menu options
C37D86:  LDY #C37D9D     ; C3/7D9D
         JMP C30640      ; Relocate cursor

; Handle D-Pad for Item menu options
C37D8C:  JSR C3072D      ; Handle D-Pad
         JSR C37D86      ; Relocate cursor
         LDY $4D         ; Cursor position
         STY $0234       ; To cursor memory
         RTS

; Draw Item menu with inventory; upload element graphics
C37DA3:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C37E13     ; C3/7E13
         JSR boxes_      ; Upload windows
         JSR bg3d_cl     ; Clear BG3 maps
         JSR C3C2F7      ; Color: Blue
         LDY #C38D16     ; Text pointer
         JSR C302F9      ; Draw "Item"
         JSR C3C2F2      ; Color: User's
         LDX #C38D10     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw options
         JSR C3A73D      ; Build desc map
         JSR C3A9A9      ; Upload elements
         JSR C36A19      ; Clear BG1 map B
         JSR C37E0D      ; Draw inventory
         JSR C382F1      ; Desc; item count
         JMP up_txt      ; Upload text

; Draw inventory after clearing tilemap (Item, Colosseum, Sell)
C37E0D:  JSR C36A15      ; Clear BG1 map A
         JMP C37F88      ; Draw inventory

; Set to condense text in Item, Colosseum, or Sell menu
C37E2B:  LDY #C37F57     ; Source LBs
         JSR bg3v        ; Queue BG3 V-Pan
         JSR C37E95      ; Load BG1 V-Data
         LDX #$000C      ; Base index
C37E4E:  LDA.L C37EDA,X  ; BG1 H-Pan data
         STA $7E9A09,X   ; Save in RAM
         DEX             ; Index -1
         BPL C37E4E      ; Loop till < 0
         LDY #$9A09      ; Src: 7E/9A09
         JSR bg1h_       ; Queue BG1 H-Pan
         LDY #$9849      ; Src: 7E/9849
         JMP bg1v_       ; Queue BG1 V-Pan

; Load BG1 vertical shift table for Item, Colosseum, or Sell menu
C37E95:  LDX $00         ; Index: 0
C37E97:  LDA.L C37EE7,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At items?
         BNE C37E97      ; Loop if not
C37EA5:  LDA.L C37EE7,X  ; Scanline data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; Top BG1 row
         JSR x16         ; x16
         REP #$21        ; 16-bit A; C-
         ADC.L C37EE7,X  ; Add V-Pan data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$006C      ; Beyond items?
         BNE C37EA5      ; Loop if not
C37ECB:  LDA.L C37EE7,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0070      ; End of table?
         BNE C37ECB      ; Loop if not
         RTS

; Draw inventory for Item, Colosseum, or Sell menu
C37F88:  JSR C383F7      ; Define $E5, $E6
         LDA #$0A        ; Rows left: 10
C37F8E:  PHA             ; Save counter
         JSR C37FA1      ; Draw item info
         INC $E5         ; Item slot +1
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C37F8E      ; Loop till last
         RTS

; Draw item's name, quantity owned, and class
C37FA1:  TDC             ; Clear A
         LDA $E5         ; Item slot
         TAY             ; Index it
         PHY             ; Memorize it
         JSR C38045      ; Choose palette
         LDA $1969,Y     ; Item quantity
         JSR C304E0      ; Turn into text
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$0011      ; X: 17
         JSR C3809F      ; Compute map ptr
         JSR C304B6      ; Draw quantity
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$0003      ; X: 3
         JSR C3809F      ; Compute map ptr
         PLY             ; Item slot
         JSR C380B9      ; Load "<item>:"
         JSR C37FD_      ; Draw string

; Fork: Draw item class
C37FE6:  JSR wm9E8B      ; WRAM: 7E/9E8B
         REP #$21        ; 16-bit A; C-
         LDA $7E9E89     ; Text position
         ADC #$0024      ; Skip item name
         STA $7E9E89     ; Save changes
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $7E9E8B     ; Item icon
         CMP #$FF        ; None?
         BEQ C3802C      ; Blank if so
         SEC             ; Prepare SBC
         SBC #!icon      ; Now 0-15
         XBA             ; Put icon in B
         LDX.W #!itm_cs  ; Letters: 7
         LDA.B #!itm_cp!h; Text ptr HB
         LDY.W #!itm_cp  ; Text ptr LBs
         JSR fw_txt      ; Load string

; Fork: Draw memorized string
C37FD_:  STZ $2180       ; End string
C37FD9:  SEP #$20        ; 8-bit A
         LDY #$9E89      ; Source LBs
         LDA #$7E        ; Source HB
         JMP C302FD      ; Draw string

; Fork: Blank item class
C3802C:  LDY.W #!itm_cs  ; Spaces: 7
         JSR spaces      ; Add to string
         BRA C37FD_      ; Draw 7 spaces

; Choose item's color for Item, Colosseum, or Sell menu
C38045:  LDA $0200       ; Root menu
         CMP #$03        ; Shop menu?
         BEQ C38085      ; Enable if so
         CMP #$07        ; Colosseum?
         BEQ C38085      ; Enable if so

; Fork: Main menu
C38056:  LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C38085      ; Enable if so
         CMP #$F7        ; Tent?
         BEQ C3808F      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C3808F      ; Branch if so
         CMP #$FD        ; Warp Stone?
         BEQ C38096      ; Branch if so
         JSR itm_cl1     ; Item class
         CMP #$06        ; Consumable?
         BNE C3808A      ; Disable if not
         LDA $D85000,X   ; Properties
         ASL A           ; Usable in field?
         BPL C3808A      ; Disable if not
C38085:  JMP C3C2F2      ; Color: User's

; Fork: Tent or Sleeping Bag
C3808F:  LDA $0201       ; Can save here?
         BMI C38085      ; Enable if so

; Fork: Set color to gray
C3808A:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         RTS

; Fork: Warp Stone
C38096:  LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BNE C38085      ; Enable if so
         BRA C3808A      ; Color: Gray

; Compute position into BG1 tilemap A
C3809F:  PHA             ; Save Y pos
         TDC             ; Clear A
         PLA             ; Y position
         JSR x64         ; x64
         STA $E7         ; Memorize it
         TXA             ; X position
         ASL A           ; Double it
         CLC             ; Prepare ADC
         ADC $E7         ; Add Y x64
         ADC #$3849      ; Add base adr
         STA $7E9E89     ; Set position
         TAX             ; Copy it to X
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         RTS

; Load owned item's name, add colon (Item, Colosseum, Sell)
C380B9:  JSR wm9E8B      ; WRAM: 7E/9E8B
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C380F6      ; Blank if so
         JSR C3C06_      ; Load item name
         LDA.B #!coln    ; Char: ":"
         STA $2180       ; Add to string
C380F5:  RTS

; Fork: Blank item name, colon, and quantity
C380F6:  LDY.W #!itm_ns+3; Spaces: 16
         JMP spaces      ; Add to string

; Adjust BG1 vertical shift amounts while list scrolls
C38105:  LDX #$0012      ; Scanline: 88th
C38108:  SEP #$20        ; 8-bit A
         LDA $7E9849,X   ; Scanline amount
         CMP #$1E        ; Last 30 lines?
         BEQ C380F5      ; Exit if so
         INX             ; RAM index +1
         PHX             ; Memorize it
         TDC             ; Clear A
         LDA $20         ; Scroll timer
         REP #$21        ; 16-bit A; C-
         LDY $41         ; Scrolling up?
         BPL C38123      ; Branch if not
         ADC #$0003      ; Timer +3
C38123:  ASL A           ; Timer x2
         TAX             ; Index it
         TAY             ; Memorize it
         LDA.L C3815F,X  ; Shift mod; R1/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PHX             ; Memorize it
         TYX             ; ROM index
         LDA.L C3816B,X  ; Shift mod; R2/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PHX             ; Memorize it
         TYX             ; ROM index
         LDA.L C38177,X  ; Shift mod; R3/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         BRA C38108      ; Do next 12 lines

; Update scroll parameters for list
C38183:  TAX             ; Index mode
         JMP (C38187,X)  ; Handle mode

; Jump table for the above
C38187:  dw C3818F       ; Scroll upward
         dw C3819C       ; Scroll downward
         dw C381A7       ; Set timer
         dw C381B0       ; Check timer

; Mode 0: Scroll upward
C3818F:  REP #$20        ; 16-bit A
         LDA #$FFFC      ; 4 px up
         STA $41         ; Set V-Speed
         BRA C381A7      ; Init timer

; Mode 1: Scroll downward
C3819C:  REP #$20        ; 16-bit A
         LDA #$0004      ; 4 px down
         STA $41         ; Set V-Speed

; Mode 2: Set timer
C381A7:  SEP #$20        ; 8-bit A
         LDX $2D         ; Queue index
         LDA #$03        ; Mode: 3
         STA $3649,X     ; Set next mode
         STA $20         ; Set timer

; Mode 3: Check timer
C381B0:  LDA $20         ; Timer expired?
         BEQ C381BC      ; Stop if so
         LDA #$20        ; Scroll BG1: Y
         TSB $46         ; Set menu flag
         SEC             ; Set to requeue
         RTS

; Fork: Stop scrolling
C381BC:  LDY $00         ; Clear Y
         STY $41         ; BG1 V-Speed: 0
         LDA #$20        ; Scroll BG1: N
         TRB $46         ; Set menu flag
         CLC             ; Set to dequeue
C381C6:  RTS

; Handle D-Pad for scrollable list, change row when wrapping
C381C7:  LDA $20         ; Scrolling now?
         BNE C381C6      ; Exit if so

; Fork: Handle up
C381CB:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C381EA      ; Branch if not
         LDA $4E         ; On first row?
         BNE C381E2      ; Go up if not
         LDA $4A         ; At top of list?
         BEQ C381C6      ; Exit if so
         DEC $50         ; List row -1
         JSR C38286      ; Queue scrolling
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor up
C381E2:  DEC $50         ; List row -1
         DEC $4E         ; Cursor row -1
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle down
C381EA:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C38210      ; Branch if not
         LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BNE C38209      ; Go down if not
         LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C381C6      ; Exit if so
         INC $50         ; List row +1
         JSR C3829E      ; Queue scrolling
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor down
C38209:  INC $50         ; List row +1
         INC $4E         ; Cursor row +1
         JSR C30EA3      ; Sound: Cursor

; Fork: Handle left
C38210:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C38249      ; Branch if not
         LDA $4D         ; On first column?
         BNE C38241      ; Branch if not
         LDA $4E         ; On top row?
         BEQ C3822D      ; Branch if so
         DEC $4E         ; Cursor row -1
         DEC $50         ; List row -1
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         STA $4D         ; Set as cursor's
         STA $4F         ; Set as list's
         JMP C30EA3      ; Sound: Cursor

; Fork: Wrap to upper, offscreen row
C3822D:  LDA $4A         ; At top of list?
         BEQ C381C6      ; Exit if so
         JSR C38286      ; Queue scrolling
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         STA $4D         ; Set as cursor's
         STA $4F         ; Set as list's
         DEC $50         ; List row -1
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor left
C38241:  DEC $4D         ; Cursor column -1
         DEC $4F         ; List column -1
         JMP C30EA3      ; Sound: Cursor

; Fork: Handle right
C38249:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3829D      ; Exit if not
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         CMP $4D         ; Cursor's there?
         BNE C3827E      ; Go right if not
         LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BEQ C3826A      ; Branch if so
         STZ $4D         ; Cursor column: 1
         STZ $4F         ; List column: 1
         INC $4E         ; Cursor row +1
         INC $50         ; List row +1
         JMP C30EA3      ; Sound: Cursor

; Fork: Wrap to lower, offscreen row
C3826A:  LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C3829D      ; Exit if so
         JSR C3829E      ; Queue scrolling
         STZ $4D         ; Cursor column: 1
         STZ $4F         ; List column: 1
         INC $50         ; List row +1
         JMP C30EA3      ; Sound: Cursor

; Fork: Move cursor right
C3827E:  INC $4D         ; Cursor column +1
         INC $4F         ; List column +1
         JMP C30EA3      ; Sound: Cursor

; Set to scroll list upward, draw row to scroll into view
C38286:  DEC $4A         ; Scroll pos -1
         DEC $49         ; Top BG1 row -1
         JSR C383F7      ; Define $E5, $E6
         JSR C382DD      ; Draw new row
         LDY #C38183     ; C3/8183
         JSR qanim0      ; Queue scroll fn
         TDC             ; Anim mode: Up
         STA $7E3649,X   ; Set scroll mode
C3829D:  RTS

; Set to scroll list downward, draw row to scroll into view
C3829E:  LDA $5B         ; Column count
         XBA             ; Put in B
         LDA $5A         ; Rows per page
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         JSR mul8        ; Sum x count
         STA $E5         ; Set SW list slot
         LDA $49         ; Top BG1 write row
;        CLC             ; Prepare ADC
         ADC $5A         ; Get bottom row +1
         ASL A           ; x2 for blank rows
         AND #$1F        ; Stay in limits
         STA $E6         ; Set BG1 write row
         INC $4A         ; Scroll pos +1
         INC $49         ; Top BG1 row +1
         JSR C382DD      ; Draw new row
         LDY #C38183     ; C3/8183
         JSR qanim0      ; Queue scroll fn
         LDA #$01        ; Anim mode: Down
         STA $7E3649,X   ; Set scroll mode
         RTS

; Draw list elements to scroll into view
C382DD:  TDC             ; Clear A
         LDA $2A         ; List type
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C382E5,X)  ; Draw row

; Jump table for the above
C382E5:  dw C37FA1       ; Inventory
         dw C34F9E       ; Magic
         dw C35256       ; Lore
         dw C353EE       ; Rage
         dw C354E3       ; Esper
         dw C39CE2       ; Gear

; Load common item's description and draw item count in Item menu
C382F1:  JSR C38308      ; Set desc ptrs
         JSR C3BFCB      ; Selected item
         JSR C35738      ; Load description
         JSR C38356      ; Count items
         JSR C3C2F2      ; Color: User's
         BRA C3837A      ; Draw item count

; Prepare item description loading
C38308:  LDX.W #!itm_d_p ; ED/7AA0
         STX $E7         ; Set ptr loc LBs
         LDX.W #!itm_d_l ; ED/6400
         STX $EB         ; Set text loc LBs
         LDA.B #!itm_d_h ; Bank: ED
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
wm9EC9:  LDX #$9EC9      ; 7E/9EC9
         STX $2181       ; Set WRAM LBs
         RTS

; Compute item data index
C38321:  XBA             ; Put item in B
         LDA #$1E        ; Item data size
         JSR mul8        ; Item x size
         TAX             ; Index product
         TDC             ; Clear A
         RTS

; Load rare item's description and draw item count
C38339:  LDX.W #!rar_d_p ; CE/FB60
         STX $E7         ; Set ptr loc LBs
         LDX.W #!rar_d_l ; CE/FCB0
         STX $EB         ; Set text loc LBs
         LDA.B #!rar_d_h ; Bank: CE
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         JSR C3572A      ; Load description
         JSR C3836B      ; Count items
         JSR C3C2F2      ; Color: User's
         BRA C3837A      ; Draw item count

; Count number of common items
C38356:  LDX #$00FF      ; Item slot: 256
         STZ $64         ; Item count: 0
C38359:  LDA $1869,X     ; Item in slot
         INC A           ; None?
         BEQ C38361      ; Exclude if so
         INC $64         ; Item count +1
C38361:  DEX             ; Item slot -1
         BPL C38359      ; Loop till < 0
         RTS

; Count number of rare items
C3836B:  TDC             ; Clear A
         TAX             ; Item slot: 1
C3836D:  LDA $7E9D89,X   ; Empty slot?
         BMI C38376      ; Branch if so
         INX             ; Item slot +1
         BRA C3836D      ; Check next slot
C38376:  TXA             ; Current slot
         STA $64         ; Set item count
         RTS

; Draw number of common or rare items
C3837A:  LDA $64         ; Item count
         JSR C304E0      ; Turn into text
         LDX #$7ABF      ; Text position
         JMP C304C0      ; Draw 3 digits

; Blank item count in corner of Item menu
C38385:  LDY #C38E4A     ; Text pointer
         JMP C302F9      ; Draw 3 spaces

; Build and draw rare item list
C3838B:  JSR C36A15      ; Clear BG1 map A
         JSR C38394      ; Build item list
         BRA C383DE      ; Draw item list

; Build rare item list
C38394:  JSR wm9D89      ; WRAM: 7E/9D89
         LDY #$0014      ; Items: 20
         LDA #$FF        ; Empty item
C3839F:  STA $2180       ; Add to list
         DEY             ; One less left
         BNE C3839F      ; Loop till last
         JSR wm9D89      ; WRAM: 7E/9D89
         LDX $1EBA       ; Item packs A+B
         STX $EF         ; Memorize them
         LDA $1EBC       ; Item pack C
         STA $F1         ; Memorize it
;        LDA $1EBD       ; ...
;        AND #$0F        ; ...
         STZ $F2         ; Clear pack D
         TDC             ; Item: Cider
         STA $E0         ; Set as current
         TAX             ; Pack index: 0
         LDA #$04        ; Item packs: 4
         STA $E1         ; Set counter
C383C4:  LDY #$0008      ; Items left: 8
         LDA $EF,X       ; 8 owned items
C383C9:  ROR A           ; Got current?
         PHA             ; Save item pack
         BCC C383D2      ; Skip if not
         LDA $E0         ; Item number
         STA $2180       ; Add to list
C383D2:  INC $E0         ; Item number +1
         PLA             ; 8 owned items
         DEY             ; One less item
         BNE C383C9      ; Loop till last
         INX             ; Pack index +1
         DEC $E1         ; One less pack
         BNE C383C4      ; Loop till last
         RTS

; Draw rare item list
C383DE:  JSR C383F7      ; Define $E6
         STZ $E5         ; Item slot: 1
         LDA #$0A        ; Rows left: 10
C383E6:  PHA             ; Save counter
         JSR C3841B      ; Draw 2 items
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C383E6      ; Loop till last
         RTS

; Define BG1 row for drawing list, plus first onscreen list slot
C383F7:  LDA $49         ; Top BG1 write row
         ASL A           ; x2 for blank rows
         AND #$1F        ; Stay in limits
         STA $E6         ; Set BG1 write row
         LDA $4A         ; Scroll position
         XBA             ; Put it in B
         LDA $5B         ; Number of columns
         JSR mul8        ; Multiply them
         STA $E5         ; Set list slot
         TDC             ; Clear A
         RTS

; Draw a row of two rare items
C3841B:  JSR C3C2F2      ; Color: User's
         LDX #$0003      ; X: 3
         JSR .recur      ; Draw item A
         LDX #$0011      ; X: 17
.recur   JSR C38436      ; Define source
         JSR C38445      ; Draw item B
         INC $E5         ; Item slot +1
         RTS

; Set source for loading rare item name
C38436:  LDY.W #!rar_ns  ; Letters: 13
         STY $EB         ; Set src size
         LDY.W #!rar_np  ; CE/FBA0
         STY $EF         ; Set src LBs
         LDA.B #!rar_np!h; Bank: CE
         STA $F1         ; Set src HB
C38444:  RTS

; Draw rare item name
C38445:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         JSR C350EC      ; Item in slot
         BEQ C38444      ; Exit if none
         JSR C38467      ; Load name
         JMP C37FD_      ; Draw name

; Load fixed-size string from table
C38467:  JSR wm9E8B      ; WRAM: 7E/9E8B
         XBA             ; String number
         LDX $EB         ; String size
         TXA             ; Put in A
         JSR mul8        ; Number x size
         TAY             ; Index product
.loop    LDA [$EF],Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE .loop       ; Loop till last
         RTS

; Handle double-clicked item
C38497:  JSR C38C2B      ; Selected item
         CMP #$FF        ; Empty slot?
         BEQ C38510      ; Fail if so
         JSR itm_cl1     ; Item class
         CMP #$06        ; Consumable?
         BNE C38515      ; Branch if not
         LDA $D85000,X   ; Item properties
         ASL A           ; Usable in field?
         BPL C38510      ; Fail if not
         JSR C38C2B      ; Selected item
         CMP #$F7        ; Tent?
         BEQ C384F8      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C384E2      ; Branch if so
         CMP #$FD        ; Warp Stone?
         BEQ C384EB      ; Branch if so
C384D3:  LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         LDA #$6F        ; C3/8A84
         STA $27         ; Queue usage menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Sleeping Bag
C384E2:  STA $E6         ; Memorize item
         LDA $0201       ; Can save here?
         BPL C38510      ; Fail if not
         BRA C384D3      ; Queue usage menu

; Fork: Warp Stone
C384EB:  STA $E6         ; Memorize item
         LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C38510      ; Fail if not
         LDA #$03        ; Event: Warp
         BRA C38501      ; Destroy item

; Fork: Tent
C384F8:  STA $E6         ; Memorize item
         LDA $0201       ; Can save here?
         BPL C38510      ; Fail if not
         LDA #$02        ; Event: Tent
C38501:  STA $0205       ; Set aftereffect
         LDA $E6         ; Item
         JSR C39D97      ; Destroy it
         JMP fdexit      ; Queue menu exit

; Fork: Unusable consumable
C38510:  LDA #$08        ; C3/1EF7
         STA $26         ; Next: Choice 1
         RTS

; Fork: Compile gear's compatible actors
C38515:  JSR wm9D89      ; WRAM: 7E/9D89
         ASL A           ; Tool class?
         BEQ C38510      ; Abort if so
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         LDX $00         ; Current: Terra
C38529:  LSR A           ; Actor can use?
         BCC C38537      ; Skip if not
         SEP #$20        ; 8-bit A
         PHA             ; Save compat.
         TXA             ; Current actor
         STA $2180       ; Add to list
         PLA             ; Compatibility
C38537:  REP #$20        ; 16-bit A
         INX             ; Actor number +1
         CPX #$000E      ; Done all 14?
         BNE C38529      ; Loop if not
         SEP #$20        ; 8-bit A
         LDA #$FF        ; Terminator
         STA $2180       ; End list

; Fork: Initialize gear data menu
C3854A:  REP #$20        ; 16-bit A
         LDA #$00E0      ; BG1 H-Shift: 224
         STA $7E9A10     ; Hide item list
         LDA #$7D8D      ; Tilemap ptr
         STA $7E9E89     ; Set item pos
         SEP #$20        ; 8-bit A
         LDA #$04        ; Cursor: Blank
         TRB $45         ; Set menu flag
         JSR C3858C      ; Stop desc/bar
         JSR C38595      ; Create arrow
         JSR C3BFCB      ; Selected item
         JSR C3C068      ; Load name
         JSR C385AD      ; Add "can be..."
         JSR C3C2F7      ; Color: Blue
         JSR C37FD9      ; Draw string
         JSR C3C2F2      ; Color: User's
         JSR C385D5      ; Draw actor list
         JSR C38671      ; Draw other info
         LDA #$64        ; C3/8983
         STA $26         ; Next: Sustain menu
         JSR C30F25      ; Queue text upload
         JMP C30F89      ; Dequeue desc DMA

; Disable scrollbar and freeze description
C3858C:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         RTS

; Add " can be used by:" after item name
C385AD:  LDX #$0001      ; Skip item icon
C385B0:  LDA $7E9E8B,X   ; Item letter
         CMP #$FF        ; Terminator?
         BEQ C385B8      ; Branch if so
         INX             ; RAM index +1
         CPX.W #!itm_ns  ; Done 12 chars?
         BNE C385B0      ; Loop if not
C385B8:  LDY $00         ; ROM index: 0
C385BA:  PHX             ; Save RAM index
         TYX             ; ROM index
         LDA.L C38D34,X  ; Message letter
         PLX             ; RAM index
         STA $7E9E8B,X   ; Add to string
         INX             ; RAM index +1
         INY             ; ROM index +1
         CPY #$0011      ; Done 17 chars?
         BNE C385BA      ; Loop if not
         RTS

; Filter and draw gear's list of compatible actors
C385D5:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         LDX $00         ; List slot: 1
C385DD:  LDA $7E9D89,X   ; Eligible actor
         BMI C38623      ; Branch if end
         STA $E5         ; Memorize actor
         LDY $00         ; Actor slot: 1
         STY $E7         ; Save actor slot

; Fork: Exclude if never recruited or dead Shadow
C385E9:  STX $F3         ; Save list slot
         LDA $E5         ; Eligible actor
         CMP $1600,Y     ; In actor slot?
         BNE C3860A      ; Try next if not
         REP #$20        ; 16-bit A
         LDA $E7         ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Showable actors
         AND.L C39C67,X  ; Has our actor?
         SEP #$20        ; 8-bit A
         BEQ C3861B      ; Skip if not
         LDA $E7         ; Actor slot
         STA $2180       ; Add to new list
         BRA C3861B      ; Do next actor

; Fork: Try next actor in SRAM block
C3860A:  REP #$21        ; 16-bit A; C-
         TYA             ; Actor's address
         ADC #$0025      ; Point to next
         TAY             ; Reindex it
         SEP #$20        ; 8-bit A
         INC $E7         ; Actor slot +1
         LDA $E7         ; Actor slot
         CMP #$10        ; Done all 16?
         BNE C385E9      ; Loop if not

; Fork: Handle next eligible actor
C3861B:  LDX $F3         ; List slot
         INX             ; List slot +1
         CPX #$0010      ; Done all 16?
         BNE C385DD      ; Loop if not

; Fork: End and draw new list
C38623:  LDA #$FF        ; Terminator
         STA $2180       ; End list
         LDX $00         ; List slot: 1
C3862A:  TDC             ; Clear A
         LDA $7E9E09,X   ; Actor in slot
         BMI C38652      ; Exit if none
         PHX             ; Save slot
         PHX             ; Save slot
         REP #$20        ; 16-bit A
         ASL A           ; Actor x2
         TAX             ; Index it
         LDA.L C36969,X  ; Actor address
         STA $67         ; Memorize it
         PLX             ; List slot
         TXA             ; Put in A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C38653,X  ; Position
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         JSR C334CF      ; Draw name
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000E      ; Done all 14?
         BNE C3862A      ; Loop if not
C38652:  RTS

; Draw all gear info except compatible actors
C38671:  JSR C36A41      ; Clear BG3 map B
         JSR C3C2F7      ; Color: Blue
         LDX #C38D45     ; Text ptrs loc
         LDA #$09        ; Strings: 9
         JSR C369BA      ; Draw stat names

; Fork: Draw stat modifiers
C3868E:  JSR C3C2F2      ; Color: User's
         JSR C3BFCB      ; Selected item
         JSR C38321      ; Compute index
;        TDC             ; Terminator
         STA $7E9E8D     ; Set mod B3
         STA $7E9E8E     ; Set mod B4
         LDY #$8445      ; Tilemap ptr
         JSR C33519      ; Set position
;        TDC             ; Clear A
         LDA $D85010,X   ; Stat mods LB
         PHA             ; Memorize them
         AND #$0F        ; Vigor index
         ASL A           ; Double it
         JSR C38836      ; Draw modifier
         LDY #$84C5      ; Tilemap ptr
         JSR C33519      ; Set position
;        TDC             ; Clear A
         PLA             ; Stat mods LB
         AND #$F0        ; Speed index
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         JSR C38836      ; Draw modifier
         LDY #$8545      ; Tilemap ptr
         JSR C33519      ; Set position
         LDX $4216       ; Item index
;        TDC             ; Clear A
         LDA $D85011,X   ; Stats mods HB
         PHA             ; Memorize them
         AND #$0F        ; Stamina index
         ASL A           ; Double it
         JSR C38836      ; Draw modifier
         LDY #$85C5      ; Tilemap ptr
         JSR C33519      ; Set position
;        TDC             ; Clear A
         PLA             ; Stat mods HB
         AND #$F0        ; Mag.Pwr index
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         JSR C38836      ; Draw modifier

; Fork: Draw defensive properties
C38703:  JSR itm_cl2     ; Item class
         DEC A           ; Weapon?
         BEQ C38746      ; Branch if so
         LDA $D85014,X   ; Defense
         JSR C304E0      ; Turn into text
         LDX #$86C3      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDX $4216       ; Item index
         LDA $D85015,X   ; Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$87C3      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C387EB      ; Draw evasions
         JSR C388A0      ; Draw 50% elems
         JSR C38959      ; Draw other ones
         JSR C3C2F7      ; Color: Blue
         LDX #C38D69     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C369BA      ; Draw elem types
         BRA C387C7      ; Do spell taught

; Fork: Draw offensive properties
C38746:  JSR C3879C      ; Draw Bat.Pwr
         JSR C387EB      ; Draw evasions
         JSR C3C2F7      ; Color: Blue
         LDY #C38E1D     ; Text pointer
         JSR C302F9      ; Draw "Attack"
         JSR C388A0      ; Draw elements
         JSR C3C2F2      ; Color: User's
         LDX $4216       ; Item index
         LDA $D85013,X   ; Allows Runic?
         PHA             ; Push properties
         PHA             ; Push properties
         BPL C3876E      ; Branch if not
         LDY #C38E30     ; Text pointer
         JSR C302F9      ; Draw "Runic"
C3876E:  PLA             ; Properties
         ASL A           ; 2-hand OK?
         BPL C38781      ; Branch if not
         LDY #C38E38     ; Text pointer
         JSR C302F9      ; Draw "2-hand"
C38781:  PLA             ; Properties
         AND #$02        ; Can SwdTech?
         BEQ C38794      ; Exit if not
         LDY #C38E26     ; Text pointer
         JMP C302F9      ; Draw "SwdTech"
C38794:  RTS

; Draw weapon's Bat.Pwr in gear data menu
C3879C:  JSR C3BFCB      ; Item
         CMP #$16        ; Soul Sabre?
         BEQ C387C0      ; Hide if so
         CMP #$1C        ; Atma Weapon?
         BEQ C387C0      ; Hide if so
         CMP #$51        ; Dice?
         BEQ C387C0      ; Hide if so
         CMP #$52        ; Fixed Dice?
         BEQ C387C0      ; Hide if so
         LDA $D85014,X   ; Bat.Pwr
         JSR C304E0      ; Turn into text
         LDX #$8643      ; Text position
         JMP C304C0      ; Draw 3 digits

; Fork: Hide power
C387C0:  LDY #C38D71     ; Text pointer
         JMP C302F9      ; Draw "???"

; Draw spell taught by armor, including learning rate
C387C7:  JSR C3C2F2      ; Color: User's
         LDX $4216       ; Item index
         REP #$20        ; 16-bit A
         LDA $D85003,X   ; Spell and rate
         STA $E0         ; Memorize them
         SEP #$20        ; 8-bit A
         XBA             ; Rate = 0?
         BEQ C38794      ; Exit if so
         LDY #$832F      ; Tilemap ptr
         JSR C33519      ; Set position
         JMP C35AED      ; Draw string

; Draw Evade and MBlock modifiers for gear data menu
C387EB:  LDY #$8743      ; Tilemap ptr
         JSR C33519      ; Set position
         LDX $4216       ; Item index
         TDC             ; Clear A
         LDA $D8501A,X   ; Evasion mods
         PHA             ; Memorize them
         AND #$0F        ; Evade index
         ASL A           ; x2
         ASL A           ; x4
         JSR C3881A      ; Draw modifier
         LDY #$8843      ; Tilemap ptr
         JSR C33519      ; Set position
         LDX $4216       ; Item index
         TDC             ; Clear A
         PLA             ; Evasion mods
         AND #$F0        ; MBlock index
         LSR A           ; ÷2
         LSR A           ; ÷4
C3881A:  TAX             ; Index it
         LDA.L C38854,X  ; Sign
         STA $7E9E8B     ; Add to string
         REP #$20        ; 16-bit A
         LDA.L C38854+1,X; Modifier
         STA $7E9E8C     ; Add to string
         BRA C38847      ; Draw modifier

; Draw a non-evasion stat modifier for gear data menu
C38836:  TAX             ; Modifier index
         REP #$20        ; 16-bit A
         LDA.L C38880,X  ; Sign and modifier
         STA $7E9E8B     ; Add to string
C38847:  JMP C37FD9      ; Draw modifier

; Build and draw list of attack or halved elements
C388A0:  LDX $4216       ; Item index
         LDA $D8500F,X   ; Elements
         JSR C388AE      ; Build list
         LDX #$7BCD      ; Tilemap ptr
         BRA C388FE      ; Draw list

; Build and draw list of absorbed, nulled, and weak elements
C38959:  LDX $4216       ; Item index
         LDA $D85016,X   ; Absorbed elements
         JSR C388AE      ; Build list
         LDX #$7BE9      ; Tilemap ptr
         JSR C388FE      ; Draw list
         LDX $4216       ; Item index
         LDA $D85017,X   ; Nulled elements
         JSR C388AE      ; Build list
         LDX #$7CCD      ; Tilemap ptr
         JSR C388FE      ; Draw list
         LDX $4216       ; Item index
         LDA $D85018,X   ; Weak points
         JSR C388AE      ; Build list
         LDX #$7CE9      ; Tilemap ptr
;        BRA C388FE      ; Draw list

; Draw current list of elements
C388FE:  STX $EB         ; Set dest LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
         TDC             ; Clear A
         TAX             ; Index: 0
C38900:  TDC             ; Clear A
         LDA $7EAA8D,X   ; Element to draw
         BMI C38926      ; Exit if no more
         PHX             ; Save list index
         REP #$20        ; 16-bit A
         ASL A           ; Element x2
         TAX             ; Index it
         LDA.L C38927,X  ; Tilemap data
         JSR C38937      ; Draw element
         LDA $EB         ; Tilemap ptr
         CLC             ; ...
         ADC #$0004      ; Skip 2 tiles
         STA $EB         ; Save changes
         SEP #$20        ; 8-bit A
         PLX             ; List index
         INX             ; List index +1
         CPX #$0006      ; Done 6 entries?
         BNE C38900      ; Loop if not
C38926:  RTS

; Base tile attributes for each element
C38927:  dw $3580        ; Water
         dw $3584        ; Earth
         dw $3588        ; Pearl
         dw $358C        ; Wind
         dw $3590        ; Poison
         dw $3594        ; Lightning
         dw $3598        ; Ice
         dw $359C        ; Fire

; Build current list of elements
C388AE:  LDY #$AA8D      ; 7E/AA8D
         STY $2181       ; Set WRAM LBs
         STZ $E0         ; Current: Water
         LDY #$0008      ; Elements: 8
C388B9:  ROL A           ; Draw current?
         BCC C388C3      ; Skip it if not
         PHA             ; Save elements
         LDA $E0         ; Current element
         STA $2180       ; Add to list
         PLA             ; Elements left
C388C3:  INC $E0         ; Elem number +1
         DEY             ; One less left
         BNE C388B9      ; Loop till last
         LDA #$FF        ; Terminator
         STA $2180       ; End list
         RTS

; Draw current element
C38937:  STA [$EB]       ; Set NW tile
         LDY #$0040      ; Map ptr: SW
         INC A           ; Tile num +1
         STA [$EB],Y     ; Set SW tile
         LDY #$0002      ; Map ptr: NE
         INC A           ; Tile num +1
         STA [$EB],Y     ; Set NE tile
         LDY #$0042      ; Map ptr: SE
         INC A           ; Tile num +1
         STA [$EB],Y     ; Set SE tile
C38982:  RTS

; 64: Sustain non-shifted gear data menu
C38983:  LDA $08         ; Pushing A?
         BMI C3898F      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C389A8      ; Branch if not
C3898F:  LDA #$FF        ; Status: Off
         STA $99         ; Disable arrow
         LDA #$0A        ; Frames: 10
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$5E        ; C3/89E6
         STA $27         ; Queue: Moved menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         JMP C30EB2      ; Sound: Click

; Fork: Handle B
C389A8:  LDA $09         ; Pushing B?
         BPL C38982      ; Exit if not
         LDA #$FF        ; Status: Off
         STA $99         ; Disable arrow
         LDX #$7B49      ; Tilemap ptr
         LDY #$0500      ; Bytes: 1280
         JSR clr_ram     ; Clear BG3b
         LDA #$04        ; Show cursor: Y
         TSB $45         ; Set menu flag
         JSR C3BC0_      ; Create scrollbar
         JSR desc_on     ; Description: On
         JSR C30F39      ; Queue BG3 upload
         JSR C31368      ; Upload it now
         TDC             ; BG1 H-Shift: 0
         STA $7E9A10     ; Unhide item list
         JSR C38510      ; Next: Choice 1
         JMP C30EA9      ; Sound: Cursor

; 5E: Sustain shifted gear data menu
C389E6:  LDA $09         ; No-autofire keys
         BIT #$81        ; Using B or right?
         BEQ C38982      ; Exit if not
C389F2:  JSR C30EA9      ; Sound: Cursor
         LDA #$0A        ; Frames: 10
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$64        ; C3/8983
         STA $27         ; Queue screen 1
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
;        BRA C38595      ; Create arrow

; Create arrow for gear data menu
C38595:  LDA #$01        ; Status: On
         STA $99         ; Enable arrow
         LDY #C37A19     ; C3/7A19
         JSR qanim1      ; Queue OAM fn
         LDY #$8008      ; Pos: 8, 128
         JMP objpos      ; Set sprite's

; Draw item usage menu
C38A0E:  JSR C36A28      ; Clear BG2 map A
         LDX #C38A3B     ; C3/8A3B
         JSR boxes_      ; Upload windows
         JSR C36A19      ; Clear BG1 map B
         LDY #$FFC0      ; X: -64 = 448
         STY $35         ; Set BG1 X-Pos
         LDA #$02        ; Portrait row bit
         TSB $45         ; Ignore back row
         JSR C3318A      ; Draw party info
         JSR C38A47      ; Draw item info
         JMP up_txt      ; Upload text maps

; Draw item info for item usage menu
C38A47:  JSR C3C2F2      ; Color: User's
         LDY #C38E41     ; Text pointer
         JSR C302F9      ; Draw "Owned:"
         LDY #$790B      ; Tilemap ptr
         JSR C33519      ; Set position
         JSR C3BFCB      ; Selected item
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name

; Draw quantity owned for item usage menu
C38A6D:  JSR C3C2F2      ; Color: User's
         TDC             ; Clear A
         LDA $28         ; Item's slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         JSR C304E0      ; Turn into text
         LDX #$7A93      ; Text position
         JMP C304B6      ; Draw 2 digits

; 6F: Initialize item usage menu
C38A84:  JSR C32A76      ; Init variables
         JSR C38A0E      ; Draw menu
         JSR C307B0      ; Queue cursor OAM
         LDA #$40        ; No cursor memory
         TSB $45         ; Set menu flag
         LDA #$70        ; Queue: Sustain menu
         JMP C32AA5      ; Next: Fade-in

; 70: Sustain item usage menu
C38A96:  JSR C30EFD      ; Queue stats upload
         JSR C30F61      ; And item info's
         LDA $08         ; Pushing A?
         BPL C38AAC      ; Branch if not
         JSR C38C2B      ; Item
         CMP #$E7        ; Rename Card?
         BEQ C38AC0      ; Branch if so
         JSR C38AE7      ; Handle item usage

; Fork: Handle B
C38AAC:  LDA $09         ; Pushing B?
         BPL C38ABF      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C38AB5:  LDA #$42        ; Allow back row
         TRB $45         ; And cursor memory
         LDA #$77        ; C3/1B35
         STA $27         ; Queue Item menu
         STZ $26         ; Next: Fade-out
C38ABF:  RTS

; Fork: Rename Card
C38AC0:  JSR C32D0B      ; Define Y
         LDA $0000,Y     ; Actor
         CMP #$0E        ; Guest?
         BCS C38AE0      ; Fail if so
         STY $0206       ; Save actor adr
         JSR C30EB2      ; Sound: Click
         LDA #$FE        ; Actor renaming
         STA $0205       ; Set next menu
         JSR fdexit      ; Queue menu exit
         LDA #$E7        ; Item number
         JMP C39D97      ; Destroy item

; Fork: Prevent guest renaming
C38AE0:  JMP C3B66F      ; Buzzer + Mosaic

; Handle item usage, excluding Rename Card
C38AE7:  JSR C32D0B      ; Target's address
         JSR C38B3D      ; Valid target?
         BCC C38B0A      ; Fail if not
         JSR C30EE5      ; Play heal sound
         JSR C38B11      ; Heal & destroy
         JSR C38A6D      ; Redraw quantity
         JSR C32C01      ; Redraw party
         TDC             ; Clear A
         LDA $28         ; Item's slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         BNE C38ABF      ; Exit if not 0
         BRA C38AB5      ; Close submenu
C38B0A:  JMP C3B66F      ; Buzzer + Mosaic

; Heal item's target, destroy item
C38B11:  JSR C38B1A      ; Heal target
         JSR C38C2B      ; Selected item
         JMP C39D97      ; Destroy item

; Adjust item target's HP, MP, and status
C38B1A:  LDA $0014,Y     ; Status LB
         STA $F8         ; Set target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set target's
         PHY             ; Save index
         JSR C38C2B      ; Item number
         LDX #$0002      ; Mode: Item
         JSL $C20009     ; Get new status
         PLY             ; Actor's address
         LDA $FC         ; Status LB
         STA $0014,Y     ; Set actor's
         LDA $FF         ; Status HB
         STA $0015,Y     ; Set actor's
         JMP C38C33      ; Heal HP & MP

; Determine whether item target is valid
C38B3D:  LDA $0014,Y     ; Wound status?
         BMI C38B85      ; Branch if so
         JSR C38C2B      ; Item
         CMP #$FE        ; Dried Meat?
         BEQ C38BC4      ; Branch if so
         CMP #$E8        ; Tonic?
         BEQ C38BC4      ; Branch if so
         CMP #$E9        ; Potion?
         BEQ C38BC4      ; Branch if so
         CMP #$EA        ; X-Potion?
         BEQ C38BC4      ; Branch if so
         CMP #$EB        ; Tincture?
         BEQ C38BD5      ; Branch if so
         CMP #$EC        ; Ether?
         BEQ C38BD5      ; Branch if so
         CMP #$ED        ; X-Ether?
         BEQ C38BD5      ; Branch if so
         CMP #$F1        ; Revivify?
         BEQ C38B8E      ; Branch if so
         CMP #$F2        ; Antidote?
         BEQ C38BBB      ; Branch if so
         CMP #$F3        ; Eyedrop?
         BEQ C38B97      ; Branch if so
         CMP #$F4        ; Soft?
         BEQ C38BA0      ; Branch if so
         CMP #$F5        ; Remedy?
         BEQ C38BB2      ; Branch if so
         CMP #$EE        ; Elixir?
         BEQ C38BE5      ; Branch if so
         CMP #$F8        ; Green Cherry?
         BEQ C38BA9      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BNE C38BD0      ; Fail if not
         BRA C38C11      ; Handle S.Bag

; Fork: Fenix Down
C38B85:  JSR C38C2B      ; Item
         CMP #$F0        ; Fenix Down?
         BEQ C38BE3      ; Succeed if so
         BRA C38BD0      ; Make item fail

; Fork: Revivify
C38B8E:  LDA $0014,Y     ; Status
         AND #$02        ; Zombie?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Eyedrop
C38B97:  LDA $0014,Y     ; Status
         LSR A           ; Dark?
         BCC C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Soft
C38BA0:  LDA $0014,Y     ; Status
         ASL A           ; Petrify?
         BPL C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Green Cherry
C38BA9:  LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Remedy
C38BB2:  LDA $0014,Y     ; Dark? Poison?
         AND #$65        ; Imp? Petrify?
         BEQ C38BD0      ; Fail if none
         BRA C38BE3      ; Make item work

; Fork: Antidote
C38BBB:  LDA $0014,Y     ; Status
         AND #$04        ; Poison?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Dried Meat, Tonic, Potion, X-Potion
C38BC4:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C38BD0      ; Fail if any
         JSR C32B9A      ; At full HP?
         BCC C38BE3      ; Succeed if not

; Fork: Make item fail
C38BD0:  CLC             ; Mark failure
         RTS

; Fork: Tincture, Ether, X-Ether
C38BD5:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C38BD0      ; Fail if any
         JSR C32BBC      ; At full MP?
         BCS C38BD0      ; Fail if so

; Fork: Make item work
C38BE3:  SEC             ; Mark success
         RTS

; Fork: Elixir
C38BE5:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C38BD0      ; Fail if any
         JSR C32B9A      ; At full HP?
         BCC C38BE3      ; Succeed if not
         JSR C32BBC      ; At full MP?
         BCC C38BE3      ; Succeed if not
         BRA C38BD0      ; Make item fail

; Fork: Sleeping Bag
C38C11:  LDA $0014,Y     ; Dark/Zom/Pois?
         AND #$F7        ; Clear/Imp/Pet/KO?
         BNE C38BE3      ; Succeed if any
         LDA $0015,Y     ; Float status?
         BMI C38BE3      ; Succeed if so
         JSR C32B9A      ; At full HP?
         BCC C38BE3      ; Succeed if not
         JSR C32BBC      ; At full MP?
         BCC C38BE3      ; Succeed if not
         BRA C38BD0      ; Make item fail

; Get selected recovery item
C38C2B:  TDC             ; Clear A
         LDA $28         ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         RTS

; Handle HP and MP recovery from item
C38C33:  JSR C38C2B      ; Item
         JSR C38321      ; Compute index
         JSR C38CCD      ; Load item power
         LDA $D85013,X   ; Fixed healing?
         PHA             ; Save properties
         BMI C38C76      ; Branch if not
         AND #$08        ; Affects HP?
         BEQ C38C5C      ; Branch if not

; Fork: Fixed HP healing
C38C4D:  TYX             ; Actor's address
         REP #$21        ; 16-bit A; C-
         LDA $B2         ; Item's power
         ADC $09,X       ; Add target's HP
         STA $09,X       ; Set target's HP
         JSR C32B9A      ; Enforce max HP

; Fork: Fixed MP healing
C38C5C:  PLA             ; Properties
         AND #$10        ; Affects MP?
         BEQ C38CD5      ; Exit if not
         REP #$21        ; 16-bit A; C-
         LDA $B2         ; Item's power
         BRA C38CA_      ; Restore MP

; Fork: Fractional HP healing
C38C76:  AND #$08        ; Affects HP?
         BEQ C38CA0      ; Branch if not
         LDX $0B,Y       ; Max HP
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         JSR C38CD6      ; Max HP x Pwr/16
         TYX             ; Actor's address
         ADC $09,X       ; Add target's HP
         STA $09,X       ; Set target's HP
         JSR C32B9A      ; Enforce max HP

; Fork: Fractional MP healing
C38CA0:  PLA             ; Properties
         AND #$10        ; Affects MP?
         BEQ C38CD5      ; Exit if not
         LDX $0F,Y       ; Max MP
         JSR C30D65      ; Add gear bonus
         JSR C30D9F      ; Cap at 999
         JSR C38CD6      ; Max MP x Pwr/16
C38CA_:  TYX             ; Actor's address
         ADC $0D,X       ; Add target's MP
         STA $0D,X       ; Set target's MP
         JMP C32BBC      ; Enforce max MP

; Load recovery item's power
C38CCD:  LDA $D85014,X   ; Item's power
         STA $B2         ; Memorize it
         STZ $B3         ; Clear HB
C38CD5:  RTS

; Multiply max HP or MP by item's power, divide by 16
C38CD6:  PHY             ; Save Y
         LDY $F3         ; Max HP or MP
         LDA $B2         ; Item's power
         JSR mul16       ; Power x max
         STX $E9         ; Set gain LBs
         STA $EB         ; Set gain B3
         STZ $EC         ; Clear byte 4
         REP #$20        ; 16-bit A
         LDX #$0004      ; Loop counter
.loop    LSR $EB         ; Halve HB
         ROR $E9         ; Halve LBs w/ C
         DEX             ; Counter -1
         BNE .loop       ; Loop till 0
         PLY             ; Restore Y
         LDA $E9         ; Product
         CLC             ; Prepare ADC
         RTS

; Load navigation data for Equip menu options
C38E50:  LDY #C38E5F     ; C3/8E5F
         JMP C305FE      ; Load navig data

; Handle D-Pad for Equip menu options
C38E56:  JSR C3072D      ; Handle D-Pad
C38E59:  LDY #C38E64     ; C3/8E64
         JMP C30640      ; Relocate cursor

; Load navigation data for Equip menu slot selection
C38E6C:  LDY #C38E7B     ; C3/8E7B
         JMP C305FE      ; Load navig data

; Handle D-Pad for Equip menu slot selection
C38E72:  JSR C3072D      ; Handle D-Pad
C38E75:  LDY #C38E80     ; C3/8E80
         JMP C30640      ; Relocate cursor

; Load navigation data for equipment browsing
C38E88:  LDY #C38EA6     ; C3/8EA6
         JMP C305FE      ; Load navig data

; Handle D-Pad for equipment browsing (over 9 items)
C38E8E:  JSR C381C7      ; Handle D-Pad
C38E91:  LDY #C38EAB     ; C3/8EAB
         JMP C30648      ; Relocate cursor

; Handle D-Pad for equipment browsing (9 items or less)
C38E9D:  JSR C3072D      ; Handle D-Pad
C38EA0:  LDY #C38EAB     ; C3/8EAB
         JMP C30640      ; Relocate cursor

; Load navigation data for Relic menu options
C38EBD:  LDY #C38ECC     ; C3/8ECC
         JMP C305FE      ; Load navig data

; Handle D-Pad for Relic menu options
C38EC3:  JSR C3072D      ; Handle D-Pad
C38EC6:  LDY #C38ED1     ; C3/8ED1
         JMP C30640      ; Relocate cursor

; Load navigation data for relic slot selection
C38ED5:  LDY #C38EE4     ; C3/8EE4
         JMP C305FE      ; Load navig data

; Handle D-Pad for relic slot selection
C38EDB:  JSR C3072D      ; Handle D-Pad
C38EDE:  LDY #C38EE9     ; C3/8EE9
         JMP C30640      ; Relocate cursor

; Draw party gear overview
C38EED:  JSR C36A28      ; Clear BG2 map A
         LDX #C3902E     ; C3/902E
         JSR C30341      ; Draw window
         JSR C30E52      ; Upload window
         LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C3C2F2      ; Color: User's
         JSR C38F1C      ; Handle member 1
         JSR C38F36      ; Handle member 2
         JSR C38F52      ; Handle member 3
         JSR C38F6E      ; Handle member 4
         JSR C30E28      ; Upload BG1 A+B
         JSR C36A3C      ; Clear BG3 map A
         JMP C30E6E      ; Upload BG3 A+B

; Draw text in party gear overview for member 1
C38F1C:  LDA $69         ; Nobody here?
         BMI C38F51      ; Exit if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         LDY #$390D      ; Text position
         JSR C334CF      ; Draw actor name
         STZ $28         ; Member slot: 1
         LDA #$04        ; Base Y: 4
         BRA C38F8A      ; Draw equipment

; Draw text in party gear overview for member 2
C38F36:  LDA $6A         ; Nobody here?
         BMI C38F51      ; Exit if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         LDY #$3B0D      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$01        ; Member: 2
         STA $28         ; Set member slot
         LDA #$0C        ; Base Y: 12
         BRA C38F8A      ; Draw equipment

; Draw text in party gear overview for member 3
C38F52:  LDA $6B         ; Nobody here?
         BMI C38F51      ; Exit if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         LDY #$3D0D      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$02        ; Member: 3
         STA $28         ; Set member slot
         LDA #$14        ; Base Y: 20
         BRA C38F8A      ; Draw equipment
C38F51:  RTS

; Draw text in party gear overview for member 4
C38F6E:  LDA $6C         ; Nobody here?
         BMI C38F51      ; Exit if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         LDY #$3F0D      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$03        ; Member: 4
         STA $28         ; Set member slot
         LDA #$1C        ; Base Y: 28

; Draw member's gear in party gear overview
C38F8A:  STA $E2         ; Set base Y
         LDY $67         ; Actor's address
         TDC             ; Clear A
         TAX             ; 1st: R-Hand
C38F92:  PHX             ; Push gear slot
         PHY             ; Push actor adr
         PHY             ; Push actor adr
         STZ $E5         ; X-Pos HB: 0
         LDA.L C38FD5,X  ; X position
         STA $E4         ; Memorize it
         LDA.L C38FDB,X  ; Relative Y
         CLC             ; Prepare ADC
         ADC $E2         ; Add base Y
         LDX $E4         ; X position
         JSR C3809F      ; Compute map ptr
         STZ $E0         ; Forbid "Empty"
         LDA $05,S       ; Gear slot
         CMP #$02        ; Either hand?
         BCS C38FBE      ; Branch if not
         JSR C3941D      ; Test "Empty"
C38FBE:  PLY             ; Actor's address
         LDA $001F,Y     ; Item in slot
         JSR C39479      ; Draw its name
         PLY             ; Actor's address
         INY             ; Reach next slot
         PLX             ; Gear slot
         INX             ; Point to next
         CPX #$0006      ; Done 6 slots?
         BNE C38F92      ; Loop if not
         RTS

; Load equipped item's name
C38FE1:  JSR wm9E8B      ; WRAM: 7E/9E8B
         CMP #$FF        ; Empty item?
         BNE C38FFC      ; Draw if not
         LDA $E0         ; Allow "Empty"?
         BEQ C3901F      ; Blank if not
         LDA #$FF        ; Empty item
C38FFC:  JMP C3C068      ; Load item name

; Fork: Blank item name
C3901F:  JMP C39D4F      ; Load 13 spaces

; Draw Equip menu, create portrait, update status via gear
C39032:  JSR C39093      ; Do boxes; face
         JSR C3911B      ; Draw info; status
         JSR C3C2F7      ; Color: Blue
         LDX #C3A2AE     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C369BA      ; Draw Head, Body
         JSR C3904E      ; Draw top options
         JSR C30E6E      ; Upload BG3 A+B
         JMP C39E0F      ; Queue text upload

; Draw options in Equip menu
C3904E:  JSR C3C2F2      ; Color: User's
         LDX #C3A2A6     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JMP C369BA      ; Draw text

; Draw options in Relic menu
C3905C:  JSR C3C2F2      ; Color: User's
         LDX #C3A2B2     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JMP C369BA      ; Draw text

; Draw Relic menu, memorize original relics, create portrait
C3906A:  JSR C39093      ; Do boxes; face
         JSR C393F2      ; Define Y
         LDX $23,Y       ; Relics worn
         STX $B0         ; Save for Reequip
         JSR C39131      ; Draw info; status
         JSR C3C2F7      ; Color: Blue
         LDX #C3A2B6     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C369BA      ; Draw 2x "Relic"
         JSR C3905C      ; Draw menu options
         JSR C3A6AB      ; Build desc map
         JMP C30E6E      ; Upload BG3 A+B

; Draw elements shared by Equip and Relic menus, create portrait
C39093:  JSR C39110      ; Load actor stats
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         SEP #$20        ; 8-bit A
         LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$42        ; 32x64 at $4000
         STA $2109       ; Set BG3 map loc
         JSR C3960C      ; Reset BG2 X-Pos
         JSR bg2b_cl     ; Clear BG2 A+B
         LDX #C3947F     ; C3/947F
         JSR boxes_      ; Upload windows
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C30E28      ; Upload BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR C393E5      ; Draw actor name
         JSR C361B2      ; Create portrait
         JSR C3C2F7      ; Color: Blue
         LDX #C3A34D     ; Text ptrs loc
         LDA #$12        ; Strings: 18
         JSR C369BA      ; Draw stat names
         JMP C30E6E      ; Upload BG3 A+B

; Load member's stats and properties with gear
C39110:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor
         JSL $C20006     ; Load data
         RTS

; Draw actor info in Equip menu, update status based on gear
C3911B:  JSR C39975      ; Draw hand names
         JSR C3913E      ; Do stats; status
;        JSR C3922D      ; SFC: Relic FX...
         JSR C393FC      ; Draw arms
         JSR C39435      ; Draw helmet
         JMP C39443      ; Draw armor

; Draw actor info in Relic menu, update status based on gear
C39131:  JSR C3913E      ; Do stats; status
         JSR C39451      ; Draw relic 1
         JMP C3945F      ; Draw relic 2

; Draw current stats in gear menu, update status based on gear
C3913E:  JSR C3C2F2      ; Color: User's
         JSR C39110      ; Load actor stats
         JSR C393F2      ; Actor's address
         JSR C399E8      ; Set Bat.Pwr mode
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         JSR C39207      ; Relocate stats
         JSR C391C4      ; Update status
         PEA $7E37       ; Pos for Mag.Pwr
         PEA $7DB7       ; Pos for Stamina
         PEA $7D37       ; Pos for Speed
         PEA $7CB7       ; Pos for Vigor
         PEA $7FB7       ; Pos for Evade
         PEA $80B7       ; Pos for MBlock
         LDX #$000A      ; 1st: MBlock
.loop    STX $FE         ; Save stat index
         LDA $3000,X     ; Stat value
         JSR C304E0      ; Turn into text
         PLX             ; Text position
         JSR C304C0      ; Draw 3 digits
         LDX $FE         ; Stat index
         DEX             ; Stat index -1
         DEX             ; Stat index -1
         BPL .loop       ; Loop till < 0
         JSR C393AB      ; Define Bat.Pwr
         LDX $F1         ; Load it
         STX $F3         ; Save for $052E
         JSR C3052E      ; Turn into text
         LDX #$7EB7      ; Text position
         JSR C30486      ; Draw 3 digits
         LDA $301A       ; Defense
         JSR C304E0      ; Turn into text
         LDX #$7F37      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $301B       ; Mag.Def
         JSR C304E0      ; Turn into text
         PLB             ; Restore DB
         LDX #$8037      ; Text position
         JMP C304C0      ; Draw 3 digits

; Update status based on gear (Rage denotes Auto Float)
C391C4:  JSR C393F2      ; Actor's address
         LDA $3032       ; Gear immunity
         JSR C391EC      ; Deny ailments
         LDA $3034       ; Gear auto status
         ORA $15,X       ; Add actor status
         LSR A           ; Auto Float or Rage?
         BCC C391EB      ; Exit if not
         LDA $3034       ; Gear auto status
         AND #$01        ; Auto Float?
         BEQ C391E8      ; No status if so
         LDA #$81        ; Enable Rage, Float
C391E8:  STA $15,X       ; Set actor status
C391EB:  RTS

; Cure ailments blocked by gear
C391EC:  AND #$25        ; Dark, Poison, Imp
         EOR #$FF        ; Toggle all bits
         STA $E1         ; Save immunities
         TYX             ; Actor's address
         LDA $14,X       ; Actor's status
         AND $E1         ; Lift immune ones
         STA $14,X       ; Save changes
         RTS

; Grant Float status if bestowed by gear
C391FB:  AND #$01        ; Auto Float
         LSR A           ; Put in Carry
         ROR A           ; Put in bit 7
         ORA $15,X       ; Add status
         STA $15,X       ; Set status
         RTS

; Load actor's info for Equip or Relic menu
C39207:  LDX #$003F      ; Buffer index
C3920B:  LDA $11A0,X     ; Actor info
         STA $3000,X     ; Set as current
         DEX             ; Index -1
         BPL C3920B      ; Loop till < 0
         LDA $A1         ; 2-hand flag
         STA $A0         ; Set as current
         LDA $CD         ; Genji G. flag
         STA $CE         ; Set as current
C3922D:  RTS

; Draw projected stats in Equip or Relic menu
C39233:  LDA $7E9D89     ; Empty item list?
         BEQ C3923E      ; Abort if so
         JSR C39A42      ; On a gray item?
         BCS C39241      ; Branch if not
C3923E:  JMP C39C87      ; Clear stats
C39241:  JSR C393F2      ; Actor's address
         LDA $25         ; Submenu
         CMP #$02        ; Equip menu?
         BEQ C3924E      ; Branch if so
         INY             ; Point to L-Hand
         INY             ; Point to head
         INY             ; Point to body
         INY             ; Point to relic 1
C3924E:  JSR C39A4_      ; Y = Actor address
         JSR ldgear1     ; X = Stock slot
         LDA $001F,Y     ; Equipped item
         PHA             ; Preserve it
         LDA $1869,X     ; Inventory item
         STA $001F,Y     ; Put on actor
         PHY             ; Save actor adr
         JSR C39110      ; Load actor data
         JSR C393F2      ; Base actor adr
         JSR C399E8      ; Set Bat.Pwr mode
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         JSR C39320      ; Set stat colors
         LDA $11A6       ; New Vigor
         JSR C304E0      ; Turn into text
         LDX #$7CBF      ; Text position
         LDA $3040       ; Vigor palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A4       ; New Speed
         JSR C304E0      ; Turn into text
         LDX #$7D3F      ; Text position
         LDA $3041       ; Speed palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A2       ; New Stamina
         JSR C304E0      ; Turn into text
         LDX #$7DBF      ; Text position
         LDA $3042       ; Stamina palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A0       ; New Mag.Pwr
         JSR C304E0      ; Turn into text
         LDX #$7E3F      ; Text position
         LDA $3043       ; Mag.Pwr palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         JSR C39371      ; Define Bat.Pwr
         JSR C3052E      ; Turn into text
         LDX #$7EBF      ; Text position
         LDA $3048       ; Bat.Pwr palette
         STA $29         ; Set as current
         JSR C30486      ; Draw 3 digits
         LDA $11BA       ; New Defense
         JSR C304E0      ; Turn into text
         LDX #$7F3F      ; Text position
         LDA $3044       ; Defense palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A8       ; New Evade
         JSR C304E0      ; Turn into text
         LDX #$7FBF      ; Text position
         LDA $3045       ; Evade palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11BB       ; New Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$803F      ; Text position
         LDA $3046       ; Mag.Def palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11AA       ; New MBlock
         JSR C304E0      ; Turn into text
         LDX #$80BF      ; Text position
         LDA $3047       ; MBlock palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         PLB             ; Restore DB
         PLX             ; Actor address
         PLA             ; Original item
         STA $1F,X       ; Restore gear
         RTS

; Set color for each projected stat in Equip or Relic menu
C39320:  TDC             ; Clear A
         TAX             ; Stat index: 0
C39327:  LDA.L C39369,X  ; Stat pointer
         PHX             ; Save index
         TAX             ; Index pointer
         LDA $11A0,X     ; Projected stat
         CMP $3000,X     ; Matches old?
         BEQ C3933C      ; Branch if so
         BCC C39340      ; Gray if less
         LDA #$28        ; Palette 2
         BRA C39342      ; Color: Yellow

; Fork: Use player's color
C3933C:  LDA #$20        ; Palette 0
         BRA C39342      ; Skip a line

; Fork: Gray out statistic
C39340:  LDA #$24        ; Palette 1
C39342:  PLX             ; Stat index
         STA $3040,X     ; Set stat color
         INX             ; Stat index +1
         CPX #$0008      ; Done 8 stats?
         BNE C39327      ; Loop if not

; Fork: Handle Bat.Pwr
C3934C:  JSR C39371      ; Set new Bat.Pwr
         JSR C393AB      ; Set old Bat.Pwr
         LDY $F3         ; New Bat.Pwr
         CPY $F1         ; Matches old?
         BEQ C3935E      ; Branch if so
         BCC C39362      ; Gray if less
         LDA #$28        ; Palette 2
         BRA C39364      ; Font: Yellow

; Fork: Use player's color for Bat.Pwr
C3935E:  LDA #$20        ; Palette 0
         BRA C39364      ; Skip a line

; Fork: Gray out Bat.Pwr
C39362:  LDA #$24        ; Palette 1
C39364:  STA $3048       ; Set BP color
         RTS

; Ordered index list for loading stats
C39369:  db $06          ; Vigor
         db $04          ; Speed
         db $02          ; Stamina
         db $00          ; Mag.Pwr
         db $1A          ; Defense
         db $08          ; Evade
         db $1B          ; Mag.Def
         db $0A          ; MBlock

; Define current (Status) or projected (Equip, Relic) Bat.Pwr
C39371:  LDA $A1         ; 2-hand mode?
         BEQ C3938B      ; Branch if not
         LDA $11AC       ; R-Hand's power
         BEQ C39381      ; Branch if 0
         STA $11AD       ; Set as L-Hand's
         BRA C3939A      ; Combine hands

; Fork: Two-handing L-Hand weapon
C39381:  LDA $11AD       ; L-Hand's power
         STA $11AC       ; Set as R-Hand's
         BRA C3939A      ; Combine hands

; Fork: Not two-handing a weapon
C3938B:  LDA $CD         ; Got Genji Glove?
         BNE C3939A      ; Branch if so
         LDA $11AC       ; R-Hand's power
         BEQ C3939A      ; Branch if 0
         STZ $11AD       ; L-Hand power: 0

; Fork: Combine hands' Bat.Pwr
C3939A:  LDA $11AC       ; R-Hand's power
         CLC             ; Prepare ADC
         ADC $11AD       ; Add L-Hand's
         STA $F3         ; Set Bat.Pwr LB
         TDC             ; Zero A
         ROL A           ; +1 if overflow
         STA $F4         ; Set Bat.Pwr HB
         RTS

; Define current Bat.Pwr for Equip or Relic menu
C393AB:  LDA $A0         ; 2-hand mode?
         BEQ C393C5      ; Branch if not
         LDA $300C       ; R-Hand's power
         BEQ C393BB      ; Branch if 0
         STA $300D       ; Set as L-Hand's
         BRA C393D4      ; Combine hands

; Fork: Two-handing L-Hand weapon
C393BB:  LDA $300D       ; L-Hand's power
         STA $300C       ; Set as R-Hand's
         BRA C393D4      ; Combine hands

; Fork: Not two-handing a weapon
C393C5:  LDA $CE         ; Got Genji Glove?
         BNE C393D4      ; Branch if so
         LDA $300C       ; R-Hand's power
         BEQ C393D4      ; Branch if 0
         STZ $300D       ; L-Hand power: 0

; Fork: Combine hands' Bat.Pwr
C393D4:  LDA $300C       ; R-Hand's power
         CLC             ; Prepare ADC
         ADC $300D       ; Add L-Hand's
         STA $F1         ; Set Bat.Pwr LB
         TDC             ; Zero A
         ROL A           ; +1 if overflow
         STA $F2         ; Set Bat.Pwr HB
         RTS

; Draw actor name in Equip or Relic menu
C393E5:  JSR C393F2      ; Actor's address
         JSR C3C2F2      ; Color: User's
         LDY #$7BB7      ; Text position
         JMP C334CF      ; Draw actor name

; Draw equipped armaments in Equip menu
C393FC:  JSR C3941D      ; Test Empty x2
         LDX #$7A1B      ; Tilemap ptr
         JSR C3946D      ; Set X, coords
         LDA $1F,X       ; R-Hand item
         JSR C39479      ; Draw its name
         JSR C3941D      ; Test Empty x2
         LDX #$7A9B      ; Tilemap ptr
         JSR C3946D      ; Set X, coords
         LDA $20,X       ; L-Hand item
         BRA C39479      ; Draw name

; Check if "Empty" should be drawn for both hands
C3941D:  JSR C393F2      ; Actor address
         STZ $E0         ; Forbid "Empty"
         LDA $1F,X       ; R-Hand item
         INC A           ; Nothing?
         BNE C39431      ; Forbid if not
         LDA $20,X       ; L-Hand item
         INC A           ; Nothing?
         BNE C39431      ; Forbid if not
         INC $E0         ; Allow "Empty"
C39431:  RTS

; Draw equipped helmet in Equip menu
C39435:  LDX #$7B1B      ; Tilemap ptr
         JSR C3946D      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $21,X       ; Helmet
         BRA C39479      ; Draw its name

; Draw equipped armor in Equip menu
C39443:  LDX #$7B9B      ; Tilemap ptr
         JSR C3946D      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $22,X       ; Armor
         BRA C39479      ; Draw its name

; Draw equipped relic 1 in Relic menu
C39451:  LDX #$7B1B      ; Tilemap ptr
         JSR C3946D      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $23,X       ; Relic 1
         BRA C39479      ; Draw its name

; Draw equipped relic 2 in Relic menu
C3945F:  LDX #$7B9B      ; Tilemap ptr
         JSR C3946D      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $24,X       ; Relic 2
C39479:  JSR C38FE1      ; Load item name
         JMP C37FD_      ; Draw item name

; Set text position and load actor data address
C3946D:  REP #$20        ; 16-bit A
         TXA             ; Tilemap ptr
         STA $7E9E89     ; Set position
C393F2:  SEP #$20        ; 8-bit A
         JSR C32D03      ; Actor's address
         STY $67         ; Memorize it
         TYX             ; Copy it to X
         RTS

; Set to condense text for party gear overview or final battle lineup
C39497:  LDY #C395D8     ; Source LBs
         LDA #$C3        ; Source HB
         JMP bg1v        ; Queue BG1 V-Pan

; Set to condense text in Equip or Relic menu
C394B6:  LDY #C395D8     ; Source LBs
         JSR bg3v        ; Queue BG3 V-Pan
         JSR C39520      ; Load BG1 V-Data
         LDX #$000C      ; Base index
C394D9:  LDA.L C39564,X  ; BG1 H-Pan data
         STA $7E9BC9,X   ; Save in RAM
         DEX             ; Index -1
         BPL C394D9      ; Loop till < 0
         LDY #$9BC9      ; Src: 7E/9BC9
         JSR bg1h_       ; Queue BG1 H-Pan
         LDY #$9849      ; Src: 7E/9849
         JMP bg1v_       ; Queue BG1 V-Pan

; Load BG1 vertical shift table for Equip or Relic menu
C39520:  LDX $00         ; Index: 0
C39522:  LDA.L C39571,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At item data?
         BNE C39522      ; Loop if not
C39530:  LDA.L C39571,X  ; Scanline data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; BG1 top row
         JSR x16         ; x16
         REP #$21        ; 16-bit A; C-
         ADC.L C39571,X  ; Add V-Pan data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0063      ; Beyond list?
         BNE C39530      ; Loop if not
C39555:  LDA.L C39571,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0067      ; End of table?
         BNE C39555      ; Loop if not
         RTS

; Switch to layout with options in Equip or Relic menu
C3960C:  JSR C3965D      ; Erase title
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         RTS

; Switch to layout without options in Equip or Relic menu
C39614:  JSR C3965D      ; Erase options
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         JMP C3C2F7      ; Color: Blue
                         ; ^ For "Equip"

; 36: Handle Equip menu options
C39621:  JSR C3960C      ; Switch windows
         JSR C3904E      ; Draw options
         JSR C38E56      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C39635      ; Branch if not
         JSR C30EB2      ; Sound: Click
         BRA C39664      ; Handle selection

; Fork: Handle B
C39635:  LDA $09         ; Pushing B?
         BPL C39648      ; Branch if not
         JSR C39110      ; Update field FX
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C39648:  LDA #$35        ; Init cmd: C3/1BB8
         JMP C32022      ; Handle L and R

; Draw blue "Equip" in Equip or Relic menu
C3964F:  LDY #C3A309     ; Text pointer
         JMP C302F9      ; Draw title

; Draw blue "Remove" in Equip or Relic menu
C39656:  LDY #C3A311     ; Text pointer
         JMP C302F9      ; Draw title

; Erase options and title in Equip or Relic menu
C3965D:  LDY #$790D      ; Tilemap ptr
         JSR C33519      ; Set position
         LDY #$001C      ; Spaces: 28
         JMP spacedr     ; Draw 28 spaces

; Handle selected option in Equip menu
C39664:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3966C,X)  ; Handle option

; Jump table for the above
C3966C:  dw C39674       ; EQUIP
         dw C39685       ; OPTIMUM
         dw C3968E       ; RMOVE
         dw C3969F       ; EMPTY

; Handle "EQUIP" selection in Equip menu
C39674:  JSR C39614      ; Switch windows
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C38E6C      ; Load navig data
         JSR C38E75      ; Relocate cursor
         LDA #$55        ; C3/9884
         STA $26         ; Next: Slot choice
         RTS

; Handle "OPTIMUM" selection in Equip menu
C39685:  JSR C396F0      ; Optimize gear
         JSR C3911B      ; Redo text, status
         STZ $4D         ; Cursor: "USE"
         RTS

; Handle "RMOVE" selection in Equip menu
C3968E:  JSR C39614      ; Switch windows
         JSR C39656      ; Draw blue "REMOVE"
         JSR C38E6C      ; Load navig data
         JSR C38E75      ; Relocate cursor
         LDA #$56        ; C3/98CF
         STA $26         ; Next: Slot choice
         RTS

; Handle "EMPTY" selection in Equip menu
C3969F:  JSR C396A8      ; Remove gear
         JSR C3911B      ; Redo text, status
         STZ $4D         ; Cursor: "USE"
         RTS

; Remove character's equipment
C396A8:  JSR C393F2      ; Actor address
         LDY #$0004      ; Gear slots: 4
.loop    LDA $1F,X       ; Item in slot
         JSR C39D5E      ; Put in stock
         LDA #$FF        ; Empty item
         STA $1F,X       ; Clear slot
         INX             ; Gear slot +1
         DEY             ; One less left
         BNE .loop       ; Loop till body
         RTS

; Optimize member's equipment (event command)
C396D2:  JSR C36915      ; Get party info
         LDX #$0003      ; Member slot: 4
         LDA $0201       ; Actor to equip
C396DA:  CMP $69,X       ; In member slot?
         BEQ C396E6      ; Branch if so
         DEX             ; Member slot -1
         BPL C396DA      ; Loop till last
         STP             ; Freeze game...
C396E6:  TXA             ; Member slot
         STA $28         ; Memorize it
         JSR C396F0      ; Optimize gear
         RTL

; Optimize character's equipment
C396F0:  JSR C39110      ; Get gear FX
         JSR C396A8      ; Remove gear
         JSR C393F2      ; Actor's address
         STY $F3         ; Memorize it
         LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C3971A      ; Branch if not

; Fork: Put a two-handed weapon in R-Hand
C39702:  JSR C39795      ; Get valid items
         JSR C3A150      ; Sort by power
         JSR C3983F      ; Pick 2H weapon
         LDX $F3         ; Actor's address
         STA $1F,X       ; Set R-Hand item
         JSR C39D97      ; Adjust stock
         BRA C3976B      ; Handle helmet

; Fork: Put a weapon in R-Hand
C3971A:  JSR C39795      ; Get valid items
         JSR C3A150      ; Sort by power
         JSR C39819      ; Pick a weapon
         STA $1F,X       ; Put in R-Hand
         JSR C39D97      ; Adjust stock
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BNE C39751      ; Branch if so

; Fork: Put a shield in L-Hand
C39737:  JSR C397D7      ; Get valid items
         JSR C3A150      ; Sort by defense
         JSR C39819      ; Pick a shield
         STA $20,X       ; Put in L-Hand
         JSR C39D97      ; Adjust stock
         BRA C3976B      ; Handle helmet

; Fork: Put a weapon in L-Hand
C39751:  JSR C39795      ; Get valid items
         JSR C3A150      ; Sort by power
         JSR C39819      ; Pick a weapon
         STA $20,X       ; Put in L-Hand
         JSR C39D97      ; Adjust stock

; Fork: Optimize helmet
C3976B:  JSR C39BB2      ; Get valid items
         JSR C3A150      ; Sort by defense
         JSR C39819      ; Choose helmet
         STA $21,X       ; Put on actor
         JSR C39D97      ; Adjust stock

; Fork: Optimize armor
C39780:  JSR C39BEE      ; Get valid items
         JSR C3A150      ; Sort by defense
         JSR C39819      ; Choose armor
         STA $22,X       ; Put on actor
         JMP C39D97      ; Adjust stock

; Select first non-excluded item in sorted list of compatible gear
C39819:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         TAY             ; RAM index: 0
C39821:  TDC             ; Clear A
         TAX             ; ROM index: 0
C39823:  PHX             ; Save index
         TDC             ; ...
         LDA $9D8A,Y     ; Stock slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         PLX             ; ROM index
         CMP $ED82E4,X   ; Excluded?
         BEQ C3983C      ; Skip if so
         INX             ; ROM index +1
         CPX #$000A      ; Tested 10?
         BNE C39823      ; Loop if not
         PLB             ; Restore DB
         LDX $F3         ; Actor's address
         RTS             ; Exit
C3983C:  INY             ; RAM index +1
         BRA C39821      ; Try next item

; Exclusions: Cursed Shld, Thornlet, Imp set, Atma Weapon, Drainer, Soul Sabre, Heal Rod


; Select first two-handed weapon from sorted list of compatible gear
C3983F:  LDA $7E9D89     ; List size
         BEQ C39881      ; Branch if 0
         STA $CB         ; Memorize it
         STZ $CC         ; Clear its HB
         TDC             ; Clear A
         TAY             ; RAM index: 0
C3984B:  TDC             ; Clear A
         TAX             ; ROM index: 0
C3984D:  PHX             ; Save index
         TYX             ; RAM index
         JSR ldgear3     ; Item in slot
         PLX             ; ROM index
         CMP $ED82E4,X   ; Excluded?
         BEQ C39878      ; Skip if so
         INX             ; ROM index +1
         CPX #$000A      ; Tested 10?
         BNE C3984D      ; Loop if not
         STA $C9         ; Save item
         JSR C38321      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C39878      ; Skip if not
         LDA $C9         ; Item
         RTS

; Fork: Try next weapon, ignore Gauntlet if no valid options
C39878:  INY             ; RAM index +1
         CPY $CB         ; End of list?
         BNE C3984B      ; Loop if not
         BRA C39819      ; Pick 1H weapon

; Fork: Default to empty item
C39881:  LDA #$FF        ; Empty item
         RTS

; 55: Handle selection of gear slot to fill
C39884:  JSR C38E72      ; Handle D-Pad
         JSR C39975      ; Recolor hand names
         LDA $08         ; Pushing A?
         BPL C398B4      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5F         ; Set body slot
         LDA #$57        ; C3/990F
         STA $26         ; Next: Item list
         JSR C39B59      ; Build item list
         JSR C3A150      ; Sort it by power
         JSR C39AEB      ; Cursor & Scrollbar
         LDA #$55        ; Return here if..
         STA $27         ; ..list is empty
         JSR C39233      ; Draw stat preview
         JSR C36A15      ; Blank item list
         JSR C31368      ; Refresh screen
         JMP C39CAC      ; Draw item list

; Fork: Handle B
C398B4:  LDA $09         ; Pushing B?
         BPL C398C8      ; Branch if not
         JSR C38E50      ; Load navig data
         JSR C38E59      ; Relocate cursor
         LDA #$36        ; C3/9621
         STA $26         ; Next: Option list
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C398C8:  LDA #$7E        ; Init cmd: C3/1BE5
         JMP C32022      ; Handle L and R

; 56: Handle manual gear removal
C398CF:  JSR C38E72      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C398F4      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C393F2      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TXA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $4B         ; Add cursor slot
         TAX             ; Index sum
         LDA $1F,X       ; Item in slot
         JSR C39D5E      ; Put in stock
         LDA #$FF        ; Empty item
         STA $1F,X       ; Clear gear slot
         JSR C3911B      ; Redo text, status

; Fork: Handle B
C398F4:  LDA $09         ; Pushing B?
         BPL C39908      ; Branch if not
         JSR C38E50      ; Load navig data
         JSR C38E59      ; Relocate cursor
         LDA #$36        ; C3/9621
         STA $26         ; Next: Option list
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C39908:  LDA #$7F        ; Init cmd: C3/1BF3
         JMP C32022      ; Handle L and R

; 57: Handle gear browsing
C3990F:  JSR C39AD3      ; Handle navigation
         JSR C39233      ; Draw stat preview
         LDA $08         ; Pushing A?
         BPL C39944      ; Branch if not
         JSR C39A42      ; On a gray item?
         BCC C3996E      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA $001F,Y     ; Item to unequip
         JSR C39D5E      ; Put in stock
         JSR ldgear1     ; Chosen item
         STA $001F,Y     ; Equip on actor
         JSR C39D97      ; Adjust stock
         JSR C3911B      ; Redo text, status
         BRA C3994D      ; Exit gear list

; Fork: Handle B
C39944:  LDA $09         ; Pushing B?
         BPL C3996D      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C3994D:  JSR C39C87      ; Clear stat preview
         LDA #$C1        ; Top cursor: Off
         TRB $46         ; Scrollbar: Off
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         JSR C38E6C      ; Load navig data
         LDA $5F         ; Former position
         STA $4E         ; Set cursor row
         JSR C38E75      ; Relocate cursor
         LDA #$55        ; C3/9884
         STA $26         ; Next: Body parts
C3996D:  RTS

; Fork: Invalid selection
C3996E:  JMP C3B66F      ; Buzzer + Mosaic

; Draw "R-hand" and "L-hand" in Equip menu
C39975:  LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C3998F      ; Branch if not
         JSR C393F2      ; Actor address
         LDA $1F,X       ; R-Hand item
         INC A           ; None?
         BEQ C399A6      ; Branch if so
         LDA $20,X       ; L-Hand item
         INC A           ; None?
         BEQ C399CA      ; Branch if so

; Fork: Draw both hands in blue
C3998F:  JSR C3C2F7      ; Color: Blue
         JSR C39998      ; Draw "R-hand"
         BRA C3999F      ; Draw "L-hand"

; Fork: Check if L-Hand also empty
C399A6:  LDA $20,X       ; L-Hand item
         CMP #$FF        ; None?
         BEQ C3998F      ; Blue x2 if so

; Fork: Check if two-handed weapon in L-Hand
C399AF:  JSR C38321      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C3998F      ; Blue x2 if not
         JSR C35F34      ; Color: Gray
         JSR C39998      ; Draw "R-hand"
         JSR C3C2F7      ; Color: Blue
         BRA C3999F      ; Draw "L-hand"

; Fork: Check if two-handed weapon in R-Hand
C399CA:  LDA $1F,X       ; R-Hand item
         JSR C38321      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C3998F      ; Blue x2 if not
         JSR C3C2F7      ; Color: Blue
         JSR C39998      ; Draw "R-hand"
         JSR C35F34      ; Color: Gray
;        BRA C3999F      ; Draw "L-hand"

; Fork: Draw "L-hand"
C3999F:  LDY #C3A2C3     ; Text pointer
         JMP C302F9      ; Draw "L-hand"

; Fork: Draw "R-hand"
C39998:  LDY #C3A2BA     ; Text pointer
         JMP C302F9      ; Draw "R-hand"

; Define Bat.Pwr mode (normal, doubled, or combined hands)
C399E8:  STZ $CD         ; Genji mode off
         LDA $11D8       ; Gear effects
         BIT #$10        ; Genji Glove?
         BEQ C399F3      ; Branch if not
         INC $CD         ; Pwr: Merge hands
C399F3:  STZ $A1         ; Power x2: Off
;        LDA $11D8       ; Gear effects
         BIT #$08        ; Gauntlet?
         BEQ C39A0C      ; Exit if not
         TYX             ; Actor's address
         LDA $1F,X       ; R-Hand item
         INC A           ; None?
         BEQ C39A0E      ; Branch if so
         LDA $20,X       ; L-Hand item
         INC A           ; None?
         BEQ C39A2B      ; Branch if so
C39A0C:  RTS

; Fork: Check if L-Hand also empty
C39A0E:  LDA $20,X       ; L-Hand item
         CMP #$FF        ; None?
         BEQ C39A0C      ; Exit if so

; Fork: Check if two-handed weapon in L-Hand
C39A17:  BRA C39A2_      ; Skip a line

; Fork: Check if two-handed weapon in R-Hand
C39A2B:  LDA $1F,X       ; R-Hand item
C39A2_:  JSR C38321      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C39A0C      ; Exit if not
         INC $A1         ; Power: x2
         RTS

; Check if pointing at grayed out gear
C39A42:  JSR C39A4A      ; Actor address
         TDC             ; Clear A
         LDA $4B         ; Gear list slot
         BRA C39A56      ; Analyze item

; Load address to selected body slot
C39A4A:  JSR C393F2      ; Actor's address
C39A4_:  REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $5F         ; Add body slot
         TAY             ; Move it to Y
         RTS

; Determine whether gear list entry is disabled
C39A56:  JSR ldgear2     ; Item in slot
         JSR itm_cl1     ; Item class
         STA $F6         ; Memorize it
         LDA $5F         ; Body slot
         DEC A           ; L-Hand/relic 2?
         BEQ C39AA5      ; Branch if so
         BPL C39AC3      ; If head or body

; Fork: For R-Hand or relic 1
C39A79:  LDA $0020,Y     ; L-Hand item
         BRA C39AA_      ; Skip a line

; Fork: For L-Hand or relic 2
C39AA5:  LDA $001E,Y     ; R-Hand item
C39AA_:  CMP #$FF        ; None?
         BEQ C39AC3      ; Enable if so
         JSR itm_cl1     ; Item class
         CMP #$03        ; Shield?
         BEQ C39AC5      ; Branch if so
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BEQ C39AC5      ; Branch if not
C39AC3:  SEC             ; Set to enable
         RTS

; Fork: Prevent two shields or weapons
C39AC5:  JSR itm_cl2     ; Held item's class
         CMP $F6         ; Like list item's?
         BNE C39AC3      ; Enable if not
C39AD1:  CLC             ; Set to disable
         RTS

; Handle D-Pad plus L and R for gear browsing
C39AD3:  LDA $7E9D89     ; List size
         CMP #$0A        ; Over 9 items?
         BCS C39ADE      ; Branch if so
         JMP C38E9D      ; Handle D-Pad

; Fork: Scrollable list
C39ADE:  LDA #$05        ; List type: Gear
         STA $2A         ; Set redraw mode
         JSR C31F64      ; Handle L and R
         BCS C39AD1      ; Exit if pushed
         JMP C38E8E      ; Handle D-Pad

; Initialize cursor data for list of available gear
C39AEB:  STZ $4A         ; List scroll: 0
         LDA $7E9D89     ; Number of items
         BEQ C39AD1      ; Exit if none
         PHA             ; Memorize it
         CMP #$0A        ; Over 9?
         BCS C39B06      ; Branch if so
         JSR C39DC4      ; Duplicate cursor
         JSR C38E88      ; Load navig data
         PLA             ; Number of items
         STA $54         ; Set cursor limit
         JMP C38EA0      ; Relocate cursor

; Fork: Scrollable list
C39B06:  JSR C39DC4      ; Duplicate cursor
         LDX #$6000      ; Bar range: 60 px
         STX $4204       ; Set dividend
         LDA $01,S       ; Number of items
         SEC             ; Prepare SBC
         SBC #$09        ; Deduct page size
         STA $4206       ; Set divisor
         JSR x32         ; 16-bit A; cycles
         STZ $4F         ; List col/row: 1
         SEP #$20        ; 8-bit A
         LDY $4214       ; V-Spd = Quotient
         LDA #$60        ; Y: 96
         JSR C30933      ; Create scrollbar
         JSR C38E88      ; Load navig data
         JSR C38E91      ; Relocate cursor
         PLA             ; Number of items
         SEC             ; Prepare SBC
         SBC #$09        ; Deduct page size
         STA $5C         ; Set scroll limit
         LDX #$0109      ; Onscreen rows: 9
         STX $5A         ; Onscreen cols: 1
         RTS

; Compile compatible weapons for Optimum
C39795:  PEA $0101       ; Seek: Weapons
         BRA eq_comp     ; Build list

; Compile compatible shields for Optimum
C397D7:  PEA $0303       ; Seek: Shields
         BRA eq_comp     ; Build list

; Compile compatible gear for selected body part
C39B59:  LDA $4B         ; Cursor slot
         CMP #$02        ; Either hand?
         BCC C39B72      ; Branch if so
         BEQ C39BB2      ; Or if helmet

; Compile compatible armor
C39BEE:  PEA $0202       ; Seek: Armor
         BRA eq_comp     ; Build list

; Compile compatible helmets
C39BB2:  PEA $0404       ; Seek: Helmets
         BRA eq_comp     ; Build list

; Compile compatible weapons and shields
C39B72:  PEA $0103       ; Seek: Wpn/Shld
         BRA eq_comp     ; Build list

; Compile compatible relics
C3A051:  PEA $0505       ; Seek: Relics
eq_comp: JSR C39C2A      ; Init list
         JSR C39C41      ; Define compat
         JSR C3C2F2      ; Color: User's
         LDY $00         ; Item slot: 1
.loop    LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ .next       ; Skip if so
         JSR itm_cl1     ; Item class
         CMP $01,S       ; Sought type A?
         BEQ .compat     ; Branch if so
         CMP $02,S       ; Sought type B?
         BNE .next       ; Skip if not
.compat  REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ .next       ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
.next    SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE .loop       ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         PLX             ; Clean stack
         RTS

; Initialize list of compatible gear
C39C2A:  LDX #$0008      ; List slot: 9
         LDA #$FF        ; Item slot 256
C39C2E:  STA $7E9D8A,X   ; Add to list
         DEX             ; List slot -1
         BPL C39C2E      ; Loop till < 0
         STZ $E0         ; List size: 0
wm9D8A:  LDX #$9D8A      ; 7E/9D8A
         STX $2181       ; Set WRAM LBs
         RTS

; Defaulting to item slot 256, which is unused in the SNES versions, provides a fallback
; for Optimum in case the list is empty or contains only banned items such as Cursed Shld.


; Define gear compatibility for actor
C39C41:  JSR C393F2      ; Define Y
;        TDC             ; Clear A
         LDA $00,X       ; Actor
C39C48:  ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C39C67,X  ; Compat bit
         STA $E7         ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $11D8       ; Gear effects
         AND #$20        ; Merit Award?
         BEQ C39C66      ; Exit if not
         LDA #$80        ; M.Award bit
         TSB $E8         ; Add to compat
C39C66:  RTS

; Bitfield for actor slots
C39C67:  dw $0001        ; Terra
         dw $0002        ; Locke
         dw $0004        ; Cyan
         dw $0008        ; Shadow
         dw $0010        ; Edgar
         dw $0020        ; Sabin
         dw $0040        ; Celes
         dw $0080        ; Strago
         dw $0100        ; Relm
         dw $0200        ; Setzer
         dw $0400        ; Mog
         dw $0800        ; Gau
         dw $1000        ; Gogo
         dw $2000        ; Umaro
         dw $4000        ; Guest 1
         dw $8000        ; Guest 2

; Erase projected stats in Equip or Relic menu
C39C87:  TDC             ; Clear A
         TAX             ; 1st: Vigor
         LDY #$0009      ; Stats: 9
         REP #$20        ; 16-bit A
C39C8E:  STA $7E7CBF,X   ; Clear hundreds
         INX             ; Index +1
         INX             ; Index +1
         STA $7E7CBF,X   ; Clear tens
         INX             ; Index +1
         INX             ; Index +1
         STA $7E7CBF,X   ; Clear ones
         INX             ; Index +1
         INX             ; Index +1
         TXA             ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$007A      ; Row +2, col -3
         TAX             ; Reindex it
         DEY             ; One less stat
         BNE C39C8E      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Draw and reveal list of available gear for body part
C39CAC:  LDA $7E9D89     ; Empty list?
         BEQ C39CDD      ; Abort if so
         JSR C383F7      ; Define $E5, $E6
         TDC             ; Clear A
         LDA $7E9D89     ; List size
         CMP #$09        ; Over 8 items?
         BCC C39CC0      ; Branch if not
         LDA #$09        ; Rows left: 9
C39CC0:  TAY             ; Put in Y...
C39CC1:  PHY             ; Memorize it
         JSR C39CE2      ; Draw item name
         INC $E5         ; List slot +1
         JSR e6add2      ; BG1 WR row +2
         PLY             ; Rows left
         DEY             ; One less left
         BNE C39CC1      ; Loop till last
         REP #$20        ; 16-bit A
         TDC             ; BG1 H-Shift: 0
         STA $7E9BD0     ; Unhide gear list
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C39CDD:  LDA $27         ; Old menu mode
         STA $26         ; Set as current
         RTS

; Draw name of item from list of available gear
C39CE2:  JSR C39A4A      ; Actor's address
         TDC             ; Clear A
         LDA $E5         ; Gear list slot
         JSR C39A56      ; Gray out item?
         BCS C39CF1      ; Branch if not
         LDA #$28        ; Color: Gray
         BRA C39CF3      ; Skip a line
C39CF1:  LDA #$20        ; Color: User's
C39CF3:  STA $29         ; Set palette
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$0002      ; X: 2
         JSR C3809F      ; Compute map ptr
;        TDC             ; Clear A
         LDA $E5         ; Gear list slot
         TAX             ; Index it
         JSR C39D11      ; Load item name
         JMP C37FD_      ; Draw item name

; Load name of item from list of available gear
C39D11:  JSR wm9E8B      ; WRAM: 7E/9E8B
         JSR ldgear3     ; Item in slot
         CMP #$FF        ; None?
         BEQ C39D4F      ; Blank if so
         JMP C3C068      ; Load item name

; Fork: Blank item name
C39D4F:  LDY.W #!itm_ns  ; Spaces: 13
         JMP spaces      ; Add to string

; Add item to inventory
C39D5E:  PHY             ; Save Y
         STA $E0         ; Set item to add
         LDY $00         ; Item slot: 1
C39D63:  CMP $1869,Y     ; Slot holds it?
         BEQ C39D8A      ; Qty +1 if so
         CMP #$FF        ; Empty item?
         BEQ C39D95      ; Exit if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C39D63      ; Loop if not

; Fork: Find an empty slot
C39D72:  LDY $00         ; Item slot: 1
C39D74:  LDA $1869,Y     ; Item in slot
         INC A           ; None?
         BEQ C39D7E      ; Replace if so
         INY             ; Item slot +1
         BRA C39D74      ; Try next slot

; Fork: Put item in empty slot
C39D7E:  LDA $E0         ; Item to add
         STA $1869,Y     ; Put in slot
         LDA #$01        ; Quantity: 1
         BRA C39D92      ; Assign to slot

; Fork: Quantity +1
C39D8A:  LDA $1969,Y     ; Quantity owned
         CMP #$63        ; 99?
         BEQ C39D95      ; Exit if so
         INC A           ; Quantity +1
C39D92:  STA $1969,Y     ; Save changes
C39D95:  PLY             ; Restore Y
         RTS

; Remove item from inventory
C39D97:  PHX             ; Save X
         LDX $00         ; Item slot: 1
C39D9C:  CMP $1869,X     ; Slot holds it?
         BEQ C39DA9      ; Branch if so
         INX             ; Item slot +1
         CPX #$0100      ; Done all 256?
         BNE C39D9C      ; Loop if not
         PLX             ; Restore X
         RTS

; Fork: Quantity -1
C39DA9:  DEC $1969,X     ; Quantity -1
         BNE C39DC2      ; Exit if > 0
         LDA #$FF        ; Empty item
         STA $1869,X     ; Put in slot
C39DC2:  PLX             ; Restore X
         RTS

; Duplicate cursor before browsing gear
C39DC4:  LDY #C39DDD     ; C3/9DDD
         JSR qanim2      ; Queue OAM fn
         LDY $55         ; Cursor pos
         JMP objpos      ; Set dupe's

; Update cursor indicating selected gear slot
C39DDD:  BNE C39E00      ; If mode 1

; Mode 0: Initialize cursor
C39DE5:  LDA #$01        ; Dupe: Sustain
         TSB $46         ; Set menu flag
         LDY #C3088D     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain cursor
C39E00:  LDA $46         ; Menu flags
         LSR A           ; Remove dupe?
         BCC C39E0D      ; Delete if so
         JMP oamsec      ; Set OAM; requeue
C39E0D:  CLC             ; Set to dequeue
         RTS

; Set to upload text tilemaps for Equip menu
C39E0F:  JSR C39E23      ; Queue BG3 upload
         JMP C30EFD      ; Queue BG1 upload

; Set to upload text tilemaps for Relic menu
C39E14:  JSR C30EFD      ; Queue BG1 upload
         LDA $021E       ; Frame counter
         LSR A           ; Odd value?
         BCS C39E23      ; Favor stats if so
         JMP C3A991      ; Queue desc upload

; Set to upload BG3 tilemaps A and upper B
C39E23:  LDY #$4000      ; $4000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0880      ; Bytes: 2176
         STY $19         ; Set data size
         RTS

; 58: Initialize Relic menu
C39E4B:  JSR C39E50      ; Init variables
         BRA C39E6F      ; Draw menu, etc.

; Initialize variables for Relic menu
C39E50:  JSR C3352F      ; Reset/Stop stuff
         JSR C36A08      ; Set Win1 bounds
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         STZ $99         ; Unmark Reequip
         JSR C31B99      ; Queue desc anim
         JSR C394B6      ; Set to shift text
         JSR C38EBD      ; Load navig data
         JSR C38EC6      ; Relocate cursor
         JMP C307B0      ; Queue cursor OAM

; Draw Relic menu, memorize original relics, etc.
C39E6F:  JSR C3906A      ; Draw menu, etc.
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$59        ; C3/9EB8
         STA $27         ; Queue: Option list
         JMP C33541      ; BRT:1 + NMI

; 79: Swap actor in Relic menu, retain Equip mode
C39E7D:  JSR C39E99      ; Draw menu, etc.
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C39EA8      ; Cursor & Fade-in
         LDA #$5A        ; C3/9FFD
         BRA C39EB3      ; Queue: Slot list

; 7A: Swap actor in Relic menu, retain Remove mode
C39E8B:  JSR C39E99      ; Draw menu, etc.
         JSR C39656      ; Draw blue "REMOVE"
         JSR C39EA8      ; Cursor & Fade-in
         LDA #$5C        ; C3/A10A
         BRA C39EB3      ; Queue: Slot list

; Reset Relic menu for either of the above
C39E99:  JSR C39E50      ; Init variables
         JSR C3906A      ; Draw menu, etc.
         JSR C30EFD      ; Queue BG1 upload
         JSR C39E23      ; Queue BG3 upload
         JMP C39614      ; Switch windows

; Put cursor on first relic slot, trigger fade-in
C39EA8:  LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JSR C38ED5      ; Load navig data
         JMP C38EDE      ; Relocate cursor

; Queue Equip or Remove mode after actor swap in Relic menu
C39EB3:  STA $27         ; Set queued command
         JMP C33541      ; BRT:1 + NMI

; 59: Handle Relic menu options
C39EB8:  JSR C39E23      ; Queue BG3 upload
         JSR C3960C      ; Switch windows
         JSR C3905C      ; Draw options
         JSR C38EC3      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C39ED0      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JMP C39FCF      ; Handle choice

; Fork: Handle B
C39ED0:  LDA $09         ; Pushing B?
         BPL C39EDC      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C39EEB      ; Handle Reequip

; Fork: Handle L and R, prepare for menu reset
C39EDC:  LDA #$58        ; Init cmd: C3/9E4B
         JMP C32022      ; Handle L and R

; Test Reequip activation, select menu commands accordingly
C39EEB:  JSR C39110      ; Get gear effects
         JSR C393F2      ; Actor address
         LDA $00,X       ; Actor
         CMP #$0D        ; Umaro?
         BEQ C39EFF      ; Branch if so
         JSR C39F5C      ; Trigger Reequip?
         BCS C39F06      ; Branch if so
C39EFF:  LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         CLC             ; Reequip: N
         RTS

; Fork: Triggered Reequip
C39F06:  LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         JSR C30EFD      ; Queue BG1 upload
         JSR C39E23      ; Queue BG3 upload
         JSR C39F1C      ; Handle text, etc.
         LDA #$F0        ; Frames: 240
         STA $22         ; Set fade delay
         LDA #$6C        ; C3/9FB1
         STA $26         ; Next: Late fade
         SEC             ; Reequip: Y
         RTS

; Handle Reequip activation
C39F1C:  JSR C3965D      ; Erase top text
         LDY #C3A40F     ; Text pointer
         JSR C302F9      ; Draw warning
         LDA $1D4E       ; Game options
         AND #$10        ; Optimum mode?
         BEQ C39F44      ; Branch if so

; Fork: Empty mode
C39F2C:  LDA #$6E        ; C3/1C26
         STA $27         ; Queue removal
         LDA $26         ; Menu mode
         CMP #$59        ; Relic options?
         BEQ C39F3D      ; Branch if so
         LDY #C3A3FD     ; Text pointer
         JMP C302F9      ; Draw "Empty"

; Fork: Draw "Empty" in option window
C39F3D:  LDY #C3A3EB     ; Text pointer
         JMP C302F9      ; Draw "Empty"

; Fork: Optimum mode
C39F44:  LDA #$6D        ; C3/1C1A
         STA $27         ; Queue optimizing
         LDA $26         ; Menu mode
         CMP #$59        ; Relic options?
         BEQ C39F55      ; Branch if so
         LDY #C3A405     ; Text pointer
         JMP C302F9      ; Draw "Optimum"

; Fork: Draw "Optimum" in option window
C39F55:  LDY #C3A3F3     ; Text pointer
         JMP C302F9      ; Draw "Optimum"

; Determine whether to trigger Reequip in Relic menu
C39F5C:  LDX $23,Y       ; Current relics
         CPX $B0         ; Unchanged?
         BEQ C39FA9      ; Branch if so

; Fork: Compare old and new relics
C39F6F:  LDX #$0002      ; 1st: M.Award
.loop    LDA.L reequip,X ; Reequip item
         CMP $0023,Y     ; Relic 1?
         BEQ C39FAC      ; Trigger if so
         CMP $0024,Y     ; Relic 2?
         BEQ C39FAC      ; Trigger if so
         CMP $B0         ; Old relic 1?
         BEQ C39FAC      ; Trigger if so
         CMP $B1         ; Old relic 2?
         BEQ C39FAC      ; Trigger if so
         DEX             ; Item index -1
         BPL .loop       ; Loop till < 0
C39FA9:  CLC             ; Reequip: No
         RTS             ; Exit
C39FAC:  SEC             ; Reequip: Yes
         RTS

; Relics that trigger Reequip
reequip: db $D0          ; Gauntlet
         db $D1          ; Genji Glove
         db $DA          ; Merit Award

; 6C: Handle delayed fade-out for Reequip
C39FB1:  LDA $22         ; Delay expired?
         BEQ C39FCC      ; Fade if so
         DEC $22         ; Timer -1
         LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BNE C39FCC      ; Fade if so
         LDA $09         ; Pushing B?
         BPL C39FCE      ; Exit if not
C39FCC:  STZ $26         ; Next: Fade-out
C39FCE:  RTS

; Handle selected option in Relic menu
C39FCF:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C39FD7,X)  ; Handle option

; Jump table for the above
C39FD7:  dw C39FDB       ; EQUIP
         dw C39FEC       ; REMOVE

; Handle "EQUIP" selection in Relic menu
C39FDB:  JSR C39614      ; Switch windows
         JSR C3964F      ; Draw blue "EQUIP"
         LDA #$5A        ; C3/9FFD
;        STA $26         ; Next: Slot list
         BRA C39FE_      ; Load navig data

; Handle "REMOVE" selection in Relic menu
C39FEC:  JSR C39614      ; Switch windows
         JSR C39656      ; Draw blue "REMOVE"
         LDA #$5C        ; C3/A10A
C39FE_:  STA $26         ; Next: Slot list
         JSR C38ED5      ; Load navig data
         JMP C38EDE      ; Relocate cursor

; 5A: Handle selection of relic slot to fill
C39FFD:  JSR C39E14      ; Queue text upload
         JSR C38EDB      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3A033      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5F         ; Set body slot
         LDA #$5B        ; C3/A097
         STA $26         ; Next: Relic list
         JSR C3A051      ; Get valid items
         JSR C3A150      ; Sort by Defense
         JSR C39AEB      ; Cursor & Scrollbar
         LDA #$5A        ; Return here if..
         STA $27         ; ..list is empty
         JSR C36A15      ; Clear BG1 map A
         JSR C31368      ; Refresh screen
         JSR C39CAC      ; Draw item list
         JSR C39233      ; Draw stat preview
         JSR C39E23      ; Queue BG3 upload
         JMP C31368      ; Refresh screen

; Fork: Handle B
C3A033:  LDA $09         ; Pushing B?
         BPL C3A047      ; Branch if not
         JSR C38EBD      ; Load navig data
         JSR C38EC6      ; Relocate cursor
         LDA #$59        ; C3/9EB8
         STA $26         ; Next: Option list
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C3A047:  LDA #$79        ; Init cmd: C3/9E7D
         JMP C32022      ; Handle L and R

; 5B: Handle relic browsing
C3A097:  JSR desc_on     ; Description: On
         JSR C39E14      ; Queue text upload
         JSR C39AD3      ; Handle navigation
         JSR C39233      ; Draw stat preview
         JSR C3A1D8      ; Load description

; Fork: Handle A
C3A0A7:  LDA $08         ; Pushing A?
         BPL C3A0DC      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C39A4A      ; Actor's address
         LDA $0023,Y     ; Relic to unequip
         CMP #$FF        ; None?
         BEQ C3A0C5      ; Branch if so
         JSR C39D5E      ; Put in stock
C3A0C5:  JSR ldgear1     ; Chosen item
         STA $0023,Y     ; Equip on actor
         JSR C39D97      ; Reduce stock
         JSR C39131      ; Draw info; status
         BRA C3A0E5      ; Exit list

; Fork: Handle B
C3A0DC:  LDA $09         ; Pushing B?
         BPL C3A109      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C3A0E5:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$C1        ; Top cursor: Off
         TRB $46         ; Scrollbar: Off
         JSR C39C87      ; Clear stat preview
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         JSR C38ED5      ; Load navig data
         LDA $5F         ; Former position
         STA $4E         ; Set cursor row
         JSR C38EDE      ; Relocate cursor
         LDA #$5A        ; C3/9FFD
         STA $26         ; Next: Slot list
C3A109:  RTS

; 5C: Handle relic removal
C3A10A:  JSR C39E23      ; Queue BG3 upload
         JSR C38EDB      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3A132      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C393F2      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TXA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $4B         ; Add cursor slot
         TAX             ; Index sum
         LDA $23,X       ; Relic worn
         JSR C39D5E      ; Put in stock
         LDA #$FF        ; Empty item
         STA $23,X       ; Clear relic worn
         JSR C39131      ; Draw info; status

; Fork: Handle B
C3A132:  LDA $09         ; Pushing B?
         BPL C3A146      ; Branch if not
         JSR C38EBD      ; Load navig data
         JSR C38EC6      ; Relocate cursor
         LDA #$59        ; C3/9EB8
         STA $26         ; Next: Option list
         JMP C30EA9      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C3A146:  LDA #$7A        ; Init cmd: C3/9E8B
         JMP C32022      ; Handle L and R

; Sort compatible gear by power after loading power ratings
C3A150:  LDX #$AC8D      ; 7E/AC8D
         STX $2181       ; Set WRAM LBs
         LDA $7E9D89     ; List size
         CMP #$02        ; 0 or 1 item?
         BCC C3A109      ; Exit if so
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         TDC             ; Clear A
         TAX             ; Gear slot: 1
C3A167:  LDA $7E9D8A,X   ; Inventory slot
         PHX             ; Save gear slot
         TAY             ; Index former
         LDA $1869,Y     ; Item in slot
         JSR C38321      ; Compute index
         LDA $D85014,X   ; Item's power
         STA $2180       ; Add to list
         PLX             ; Gear slot
         INX             ; Gear slot +1
         CPX $E7         ; End of list?
         BNE C3A167      ; Loop if not

; Fork: Sort list of compatible gear by power
C3A187:  DEC $E7         ; List size -1
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         TAY             ; Items done: 0
C3A190:  TDC             ; Clear A
         TAX             ; List slot: 1
C3A192:  LDA $AC8D,X     ; Item's power
         CMP $AC8E,X     ; Next is worse?
         BCS C3A1B7      ; Skip if not
         PHA             ; Memorize it
         LDA $9D8A,X     ; Item number A
         PHA             ; Memorize it
         LDA $AC8E,X     ; Item power B
         STA $AC8D,X     ; Replace A's
         LDA $9D8B,X     ; Item number B
         STA $9D8A,X     ; Replace A's
         PLA             ; Item number A
         STA $9D8B,X     ; Replace B's
         PLA             ; Item power A
         STA $AC8E,X     ; Replace B's
C3A1B7:  INX             ; List slot +1
         CPX $E7         ; End of list?
         BNE C3A192      ; Loop if not
         INY             ; Items done +1
         CPY $E7         ; Fully sorted?
         BNE C3A190      ; Loop if not
         PLB             ; Restore DB
         RTS

; Load item description for relic browsing
C3A1D8:  JSR C38308      ; Set desc ptrs
         JSR ldgear1     ; Item in slot
         JMP C35738      ; Load description

; Establish button purposes and autofire delays
C3A424:  LDA #$08        ; Initial delay
         STA $0229       ; For: General
         LDA #$03        ; Repeat delay
         STA $022A       ; For: General
         STA $0226       ; For: A in battle
         LDA #$20        ; Initial delay
         STA $0225       ; For: A in battle
         LDA $1D54       ; Game options
         ASL A           ; Custom buttons?
         BPL C3A441      ; Reset if not
         JSR C3A5C4      ; Apply user keys
         RTL             ; Exit
C3A441:  JSR C3A5D1      ; Reset buttons
         RTL

; Decode joypads for battle
C3A445:  LDA $1D54       ; Two players?
         BPL C3A458      ; Branch if not
         TDC             ; Clear A
         LDA $0201       ; Member slot
         TAX             ; Index it
         LDA $1D4F       ; Assigned pad
         AND.L C3A53D,X  ; Player 2's?
         BNE C3A45D      ; Branch if so
C3A458:  LDX $4218       ; Player 1 keys
         BRA C3A462      ; Skip a line
C3A45D:  LDX $421A       ; Player 2 keys
C3A462:  JSR C3A483      ; Decode keys
         JSR C3A4BD      ; Do autofire
         JSR C3A4F6      ; Adjust it
         BRA C3A527      ; Restore $E0+

; Decode joypads for field menu
C3A46E:  LDX $4218       ; Player 1 keys
         JSR C3A483      ; Decode keys
         JSR C3A4BD      ; Do autofire
         BRA C3A527      ; Restore $E0+

; Decode joypads for field
C3A47A:  LDX $4218       ; Player 1 keys
         JSR C3A483      ; Decode keys
C3A527:  PLY             ; $EB backup
         STY $EB         ; Restore it
         PLY             ; $E9 backup
         STY $E9         ; Restore it
         PLY             ; $E7 backup
         STY $E7         ; Restore it
         PLY             ; $E0 backup
         STY $E0         ; Restore it
         TDC             ; Clear A
         RTL

; Update non-time-based joypad keys
C3A483:  PLY             ; Pull ret adr
         PEI ($E0)       ; Push temp var
         PEI ($E7)       ; Push temp var
         PEI ($E9)       ; Push temp var
         PEI ($EB)       ; Push temp var
         PHY             ; Push ret adr
         STX $EB         ; Save pad keys
         REP #$20        ; 16-bit A
         LDA $0C         ; Former keys
         AND #$FFF0      ; Unused bits...
         STA $E0         ; Memorize them
         JSR C3A541      ; Convert keys
         LDA $0C         ; Former keys
         EOR #$FFFF      ; Invert them
         AND $06         ; Keep current
         STA $08         ; Set no-auto keys
         LDY $06         ; Pushed keys
         STY $0C         ; Set former keys
         LDA $4218       ; Player 1 keys
         ORA $421A       ; Add player 2's
         STA $04         ; Set merged keys
         SEP #$20        ; 8-bit A
         RTS

; Update slow autofire keys
C3A4BD:  REP #$20        ; 16-bit A
         LDA $06         ; Pushed keys
         AND #$FFF0      ; Clear pad type
         CMP $E0         ; Unchanged?
         SEP #$20        ; 8-bit A
         BNE C3A4E5      ; Use new if not
         LDA $0227       ; Initial delay
         BEQ C3A4D4      ; Branch if over
         DEC $0227       ; Initial delay -1
         BNE C3A4F1      ; No keys if > 0
C3A4D4:  DEC $0228       ; Repeat delay -1
         BNE C3A4F1      ; No keys if > 0
         LDA $022A       ; Delay: 3
         STA $0228       ; Set repeat timer
         LDY $06         ; Pushed keys
         STY $0A         ; Set slow keys
         RTS             ; Exit
C3A4E5:  LDA $0229       ; Delay: 8
         STA $0227       ; Set initial
         LDA $022A       ; Delay: 3
         STA $0228       ; Set repeat timer
C3A4F1:  LDY $08         ; No-autofire keys
         STY $0A         ; Set slow keys
C3A4F5:  RTS

; Adjust slow autofire keys for battle
C3A4F6:  LDA $06         ; Pushing A?
         BPL C3A517      ; Branch if not
         LDA $0225       ; Initial delay
         BEQ C3A506      ; Branch if over
         DEC $0225       ; Initial delay -1
         BNE C3A522      ; New keys if > 0
C3A506:  DEC $0226       ; Repeat delay -1
         BNE C3A522      ; New keys if > 0
         LDA $022A       ; Delay: 3
         STA $0226       ; Set repeat timer
         LDA #$80        ; Button: A
         TSB $0A         ; Add to slow keys
         RTS             ; Exit
C3A517:  LDA #$20        ; Delay: 32
         STA $0225       ; Set initial
         LDA $022A       ; Delay: 3
         STA $0226       ; Set repeat timer
C3A522:  LDA $08         ; No-autofire keys
         STA $0A         ; Set slow keys
C3A526:  RTS

; Bitfield for joypad assignments
C3A53D:  db $01          ; Member 1
         db $02          ; Member 2
         db $04          ; Member 3
         db $08          ; Member 4

; Convert pushed keys based on user settings (for SFC)
C3A541:  LDA $EB         ; Pushed keys
         AND #$0F00      ; Get D-Pad's
         STA $06         ; Set fast keys
         LDA #$0080      ; Target: A
         STA $E7         ; Set key #1
         LDA #$8000      ; Target: B
         STA $E9         ; Set key #2
         LDY $00         ; Cfg index: 0
         JSR C3A581      ; Do A and B
         LDA #$0040      ; Target: X
         STA $E7         ; Set key #1
         LDA #$4000      ; Target: Y
         STA $E9         ; Set key #2
         INY             ; Index +1
         JSR C3A581      ; Do X and Y
         LDA #$0020      ; Target: L
         STA $E7         ; Set key #1
         LDA #$0010      ; Target: R
         STA $E9         ; Set key #2
         INY             ; Index +1
         JSR C3A581      ; Do L and R
         LDA #$1000      ; Target: Start
         STA $E7         ; Set key #1
         LDA #$2000      ; Target: Select
         STA $E9         ; Set key #2
         INY             ; Index +1

; Convert two pushed keys to their respective purposes (for SFC)
C3A581:  LDA $EB         ; Pushed keys
         BIT $E7         ; Has key #1?
         BEQ C3A59B      ; Skip if not
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0220,Y     ; Key actions
         AND #$F0        ; Get key #1's
         REP #$20        ; 16-bit A
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         TAX             ; Index it
         LDA.L C3A5B4,X  ; Action bit
         TSB $06         ; Set fast key
C3A59B:  LDA $EB         ; Pushed keys
         BIT $E9         ; Has key #2?
         BEQ C3A5B3      ; Exit if not
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0220,Y     ; Key actions
         AND #$0F        ; Get key #2's
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3A5B4,X  ; Action bit
         TSB $06         ; Set fast key
C3A5B3:  RTS

; Bitfield for button purposes
C3A5B4:  dw $1000        ; End        (Start)
         dw $0080        ; Confirm    (A)
         dw $8000        ; Cancel     (B)
         dw $0040        ; Menu       (X)
         dw $4000        ; Switch     (Y)
         dw $0020        ; Page up    (L)
         dw $0010        ; Page down  (R, Select)
;        dw $2000        ; Unused

; Apply player's button settings (SFC)
C3A5C4:  LDY $1D50       ; A, B, X, Y
         STY $0220       ; Set purposes
         LDY $1D52       ; L, R, Select
         STY $0222       ; Set purposes
         RTS

; Apply default button settings
C3A5D1:  LDY #$3412      ; A, B, X, Y
         STY $0220       ; Set purposes
         LDY #$0656      ; L, R, Select
         STY $0222       ; Set purposes
         RTS

; Upload element's VWF graphics; freeze CGRAM
C3A5F6:  JSR C3A600      ; Set src and dst
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         JMP C314AC      ; Upload graphics

; Set to upload VWF string graphics (elements, ending pseudonym)
C3A600:  STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0120      ; Bytes: 288
         STY $19         ; Set data size
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         RTS

; Build tilemap for actor's pseudonym in ending
C3A611:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$0598      ; Ends at 12,23
         STY $E7         ; Set row's limit
         LDY #$0580      ; Starts at 1,23
         LDX #$2410      ; Tile 16, pal 1
         JSR C3A783      ; Build row 1
         LDY #$05D8      ; Ends at 12,24
         STY $E7         ; Set row's limit
         LDY #$05C0      ; Starts at 1,24
         LDX #$2411      ; Tile 17, pal 1
         JMP C3A783      ; Build row 2

; Load and set to upload VWF graphics for actor's pseudonym
C3A63B:  LDY #$0240      ; Tiles: 36
         JSR clr_vwf     ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDA #$06        ; Letters: 6
         STA $F1         ; Set counter
         LDX $00         ; Letter index: 0
C3A64A:  LDA $7E9E89,X   ; Letter
         JSR C3A8B1      ; Load graphics
         INX             ; Letter index +1
         DEC $F1         ; One less letter
         BNE C3A64A      ; Loop till last
         LDY #$2080      ; VRAM pointer
         BRA C3A600      ; Queue upload

; Build description tilemap for Skills submenus
C3A662:  LDX #$8049      ; Base: 7E/8049
         STX $EB         ; Set map ptr LBs
         LDY #$00BC      ; Ends at 30,3
         STY $E7         ; Set row's limit
         LDY #$0084      ; Starts at 3,3
         LDX #$3500      ; Tile 256, pal 5
         JSR C3A783      ; Do line 1, row 1
         LDY #$00FC      ; Ends at 30,4
         STY $E7         ; Set row's limit
         LDY #$00C4      ; Starts at 3,4
         LDX #$3501      ; Tile 257, pal 5
         JSR C3A783      ; Do line 1, row 2
         LDY #$013C      ; Ends at 30,5
         STY $E7         ; Set row's limit
         LDY #$0104      ; Starts at 3,5
         LDX #$3538      ; Tile 312, pal 5
         JSR C3A783      ; Do line 2, row 1
         LDY #$017C      ; Ends at 30,6
         STY $E7         ; Set row's limit
         LDY #$0144      ; Starts at 3,6
         LDX #$3539      ; Tile 313, pal 5
         JMP C3A783      ; Do line 2, row 2

; Build description tilemap for Relic menu
C3A6AB:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$01BC      ; Ends at 30,7
         STY $E7         ; Set row's limit
         LDY #$0184      ; Starts at 3,7
         LDX #$3500      ; Tile 256, pal 5
         JSR C3A783      ; Do line 1, row 1
         LDY #$01FC      ; Ends at 30,8
         STY $E7         ; Set row's limit
         LDY #$01C4      ; Starts at 3,8
         LDX #$3501      ; Tile 257, pal 5
         JSR C3A783      ; Do line 1, row 2
         LDY #$023C      ; Ends at 30,9
         STY $E7         ; Set row's limit
         LDY #$0204      ; Starts at 3,9
         LDX #$3538      ; Tile 312, pal 5
         JSR C3A783      ; Do line 2, row 1
         LDY #$027C      ; Ends at 30,10
         STY $E7         ; Set row's limit
         LDY #$0244      ; Starts at 3,10
         LDX #$3539      ; Tile 313, pal 5
         BRA C3A783      ; Do line 2, row 2

; Build description tilemap for shop menu
C3A6F4:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$04BC      ; Ends at 30,19
         STY $E7         ; Set row's limit
         LDY #$0484      ; Starts at 3,19
         LDX #$3500      ; Tile 256, pal 5
         JSR C3A783      ; Do line 1, row 1
         LDY #$04FC      ; Ends at 30,20
         STY $E7         ; Set row's limit
         LDY #$04C4      ; Starts at 3,20
         LDX #$3501      ; Tile 257, pal 5
         JSR C3A783      ; Do line 1, row 2
         LDY #$053C      ; Ends at 30,21
         STY $E7         ; Set row's limit
         LDY #$0504      ; Starts at 3,21
         LDX #$3538      ; Tile 312, pal 5
         JSR C3A783      ; Do line 2, row 1
         LDY #$057C      ; Ends at 30,22
         STY $E7         ; Set row's limit
         LDY #$0544      ; Starts at 3,22
         LDX #$3539      ; Tile 313, pal 5
         BRA C3A783      ; Do line 2, row 2

; Build description tilemap for Item or Colosseum menu
C3A73D:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$01BC      ; Ends at 30,7
         STY $E7         ; Set row's limit
         LDY #$0184      ; Starts at 3,7
         LDX #$3500      ; Tile 256, pal 5
         JSR C3A783      ; Do line 1, row 1
         LDY #$01FC      ; Ends at 30,8
         STY $E7         ; Set row's limit
         LDY #$01C4      ; Starts at 3,8
         LDX #$3501      ; Tile 257, pal 5
         JSR C3A783      ; Do line 1, row 2
         LDY #$023C      ; Ends at 30,9
         STY $E7         ; Set row's limit
         LDY #$0204      ; Starts at 3,9
         LDX #$3538      ; Tile 312, pal 5
         JSR C3A783      ; Do line 2, row 1
         LDY #$027C      ; Ends at 30,10
         STY $E7         ; Set row's limit
         LDY #$0244      ; Starts at 3,10
         LDX #$3539      ; Tile 313, pal 5
C3A783:  LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         REP #$20        ; 16-bit A
C3A785:  TXA             ; Tile attributes
         STA [$EB],Y     ; Put in tilemap
         INX             ; Tile +1
         INX             ; Tile +1
         INY             ; Index +1
         INY             ; Index +1
         CPY $E7         ; Beyond range?
         BNE C3A785      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Clear buffer for VWF description graphics
C3A796:  LDY #$0700      ; Bytes: 1792
         JMP clr_vwf     ; Clear buffer

; Update VWF description
C3A80E:  CMP #$02        ; Mode 1?
         BEQ C3A82F      ; Branch if so
         BCS C3A81B      ; If mode 2

; Mode 0: Clear description
C3A818:  JSR C3A796      ; Clear desc GFX

; Mode 2: Initialize variables
C3A81B:  STZ $8D         ; Line width: 0
         LDX $2D         ; Queue index
         LDA #$01        ; Mode: 1
         STA $3649,X     ; Next: Update
         REP #$20        ; 16-bit A
         STZ $33CA,X     ; Char index: 0
         STZ $344A,X     ; VRAM index: 0
         SEP #$20        ; 8-bit A

; Mode 1: Sustain description
C3A82F:  LDA $26         ; Menu mode
         CMP #$17        ; Item menu top?
         BEQ C3A88D      ; Blank if so
         LDA $46         ; Menu flags
         AND #$C0        ; No scrollbar?
         BEQ C3A841      ; Branch if so
         LDA $06         ; Pushed keys
         AND #$30        ; Using L or R?
         BNE C3A895      ; Reset if so
C3A841:  LDA $45         ; Menu flags
         BIT #$20        ; Ignore D-Pad?
         BNE C3A84D      ; Branch if so
         LDA $07         ; Pushed keys
         AND #$0F        ; Using D-Pad?
         BNE C3A895      ; Reset if so
C3A84D:  LDA $45         ; Menu flags
         BIT #$10        ; Clear desc?
         BNE C3A895      ; Reset if so
         TXY             ; Queue index
         LDX $344A,Y     ; VRAM index
         STX $ED         ; Memorize it
         LDX $33CA,Y     ; Char index

; Fork: Handle line break
C3A85D:  LDA $7E9EC9,X   ; Text character
         BEQ C3A89C      ; Branch if <end>
         CMP #$01        ; Line break?
         BNE C3A875      ; Branch if not
         STZ $8D         ; Line width: 0
         REP #$20        ; 16-bit A
         LDA #$0380      ; Base tile: 57
         STA $344A,Y     ; Set VRAM index
         BRA C3A87D      ; Queue upload

; Fork: Handle character
C3A875:  JSR C3A8B1      ; Load graphics

; Fork: Queue upload, advance char index
C3A87D:  INX             ; Char index +1
         LDY $2D         ; Queue index
         REP #$20        ; 16-bit A
         TXA             ; Char index
         STA $33CA,Y     ; Put in queue
         SEP #$20        ; 8-bit A
         JSR C3A991      ; Queue upload
         SEC             ; Set to requeue
         RTS

; Fork: Clear description, stop updating
C3A88D:  JSR C3A796      ; Clear desc GFX
         JSR C3A991      ; Set to upload
         CLC             ; Set to dequeue
         RTS

; Fork: Set to reset description
C3A895:  LDX $2D         ; Queue index
         STZ $3649,X     ; Mode: 0
         SEC             ; Set to requeue
         RTS

; Fork: Handle terminator
C3A89C:  LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         LDX $2D         ; Queue index
         LDA #$02        ; Mode: 2
         STA $3649,X     ; Next: Init
         SEC             ; Set to requeue
         RTS

; Make character number zero-based, clear graphics table pointer
C3A8A9:  SEC             ; Prepare SBC
         SBC #$80        ; Adjust letter
         STZ $EB         ; Table ptr LB: 0
         STZ $EC         ; Table ptr HB: 0
         RTS

; Load VWF character's graphics into string, add shadow effect
C3A8B1:  PHX             ; Save X
         JSR C3A8A9      ; Char num -128
         PHA             ; Memorize it
         XBA             ; Put it in B
         LDA #$16        ; GFX data size
         JSR mul8        ; Char x size
         REP #$21        ; 16-bit A; C-
         ADC $EB         ; Add font index
         TAY             ; Set ROM index
         SEP #$20        ; 8-bit A
         LDA #$0B        ; Rows left: 11
         STA $E5         ; Set counter
         TDC             ; Clear A
         LDA $8D         ; Textline width
         AND #$F8        ; Drop WIP tile's
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         CLC             ; Prepare ADC
         ADC $ED         ; Add VRAM index
         TAX             ; Set RAM index

; Fork: Load 1bpp row graphics, shift to fit string
C3A8D9:  PHX             ; Save RAM index
         REP #$20        ; 16-bit A
         TYX             ; ROM index
         LDA $C490C0,X   ; 12-px row GFX
         STZ $E7         ; Blank slice C
         STZ $E9         ; Clear byte 4
         STA $E8         ; Set slices A+B
         JSR C3A94F      ; Shift pixels

; Fork: Insert row segment C, copy as shadow below (2bpp)
C3A8EA:  PLX             ; RAM index
         LDA $E7         ; Slices B and C
         SEP #$20        ; 8-bit A
         ORA $7EA2B9,X   ; Add WIP plane A
         STA $7EA2B9,X   ; Set WIP plane A
         REP #$20        ; 16-bit A
         LSR A           ; Shift 1 px right
         SEP #$20        ; 8-bit A
         ORA $7EA2BC,X   ; Add WIP plane B
         STA $7EA2BC,X   ; Set WIP plane B

; Fork: Insert row segment B, copy as shadow below (2bpp)
C3A904:  REP #$20        ; 16-bit A
         LDA $E8         ; Slices A and B
         SEP #$20        ; 8-bit A
         ORA $7EA299,X   ; Add WIP plane A
         STA $7EA299,X   ; Set WIP plane A
         REP #$20        ; 16-bit A
         LSR A           ; Shift 1 px right
         SEP #$20        ; 8-bit A
         ORA $7EA29C,X   ; Add WIP plane B
         STA $7EA29C,X   ; Set WIP plane B

; Fork: Insert row segment A, copy as shadow below (2bpp)
C3A91F:  REP #$20        ; 16-bit A
         LDA $E8         ; Slices A and B
         SEP #$20        ; 8-bit A
         XBA             ; Get slice A
         ORA $7EA279,X   ; Add WIP plane A
         STA $7EA279,X   ; Set WIP plane A
         LSR A           ; Shift 1 px right
         ORA $7EA27C,X   ; Add WIP plane B
         STA $7EA27C,X   ; Set WIP plane B

; Fork: Handle next row
C3A937:  INX             ; RAM index +1
         INX             ; RAM index +1
         INY             ; ROM index +1
         INY             ; ROM index +1
         DEC $E5         ; One less row
         BNE C3A8D9      ; Loop till last

; Fork: Add character's width to line total
C3A93F:  TDC             ; Clear A
         PLA             ; Text character
         CLC             ; Prepare ADC
         ADC #$20        ; Use field format
         TAX             ; Index it
         LDA $8D         ; Line width
;        CLC             ; Prepare ADC
         ADC $C48FC0,X   ; Add char width
         STA $8D         ; Save changes
         PLX             ; Restore X
         RTS

; Shift VWF character's row for string insertion
C3A94F:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $8D         ; Line width
         AND #$07        ; WIP tile's
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         JMP (C3A95D,X)  ; Shift row

; Jump table for the above
C3A95D:  dw C3A96F       ; 0: 4 px left
         dw C3A973       ; 1: 3 px left
         dw C3A977       ; 2: 2 px left
         dw C3A97B       ; 3: 1 px left
         dw C3A97F       ; 4: Unchanged
         dw C3A98C       ; 5: 1 px right
         dw C3A988       ; 6: 2 px right
         dw C3A984       ; 7: 3 px right
;        dw C3A980       ; 8: 4 px right (unused)

; Shift VWF character's row left for string insertion
C3A96F:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A973:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A977:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A97B:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A97F:  RTS

; Shift VWF character's row right for string insertion
C3A980:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3A984:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3A988:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3A98C:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
         RTS

; Set to upload VWF description, freeze CGRAM
C3A991:  LDY #$6800      ; $6800
         STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0700      ; Bytes: 1792
         STY $19         ; Set data size
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         RTS

; Load and upload VWF graphics for all elements
C3A9A9:  LDY #$6C00      ; $6C00
         STY $F1         ; Set VRAM ptr
         TDC             ; Clear A
         TAX             ; Elem index: 0
C3A9C0:  LDA $D8E90E,X   ; Elem text char
         BEQ C3A9E2      ; Exit if none
         PHX             ; Save index
         JSR C3A9E5      ; Load graphics
         PLX             ; Elem index
         INX             ; Elem index +1
         LDY $F1         ; VRAM pointer
         JSR C3A5F6      ; Upload graphics
         REP #$21        ; 16-bit A; C-
         LDA $F1         ; VRAM pointer
         ADC #$0020      ; Skip 4 tiles
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         BRA C3A9C0      ; Do next element
C3A9E2:  JMP C30F89      ; Dequeue upload

; Load element's graphics (VWF)
C3A9E5:  PHA             ; Save text char
         LDY #$0040      ; Bytes: 64
         JSR clr_vwf     ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         PLA             ; Elem text char
         JMP C3A8B1      ; Load graphics

; 73: Initialize final battle lineup
C3A9F8:  JSR C3352F      ; Reset/Stop stuff
         JSR C36904      ; Reset BGs' X/Y
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDY #C3AC63     ; C3/AC63
         JSR C305FE      ; Load navig data
         JSR C3AC5D      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C3AAEE      ; Clear candidates
         JSR C3AAFD      ; Reset user's list
         JSR C3AB13      ; Draw menu
         JSR C39497      ; Set to shift text
         LDA #$74        ; C3/AA25
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JSR C30EFD      ; Queue text upload
         JMP C33541      ; BRT:1 + NMI

; 74: Sustain final battle lineup
C3AA25:  JSR C3AB89      ; Redraw candidates
         JSR C3ABB4      ; Redraw user's list
         JSR C3AC5A      ; Handle D-Pad
         JSR C30EFD      ; Queue text upload

; Fork: Handle B
C3AA31:  LDA $09         ; Pushing B?
         BPL C3AA63      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA $4A         ; R-List's empty?
         BEQ C3AAB1      ; Exit if so
         DEC $4A         ; R-List size -1
         TDC             ; Clear A
         LDA $4A         ; R-List size
         TAX             ; Index it
         LDA $0205,X     ; Last R-List char
         PHA             ; Save this actor
         LDA #$FF        ; Actor: None
         STA $0205,X     ; Clear R-List slot
         LDX #$000B      ; L-List slot: 12
         PLA             ; Removed actor
C3AA50:  CMP $7E9D8A,X   ; In L-List slot?
         BEQ C3AA5C      ; Enable it if so
         DEX             ; L-List slot -1
         BPL C3AA50      ; Loop till < 0
C3AA5C:  LDA #$20        ; Color: User's
         STA $7EAA8D,X   ; Set L-List name's
         RTS

; Fork: Handle actor selection
C3AA63:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C3AA99      ; Branch if so
         LDA $08         ; Pushing A?
         BPL C3AAB1      ; Exit if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; On Reset?
         BEQ C3AAA7      ; Branch if so
         CMP #$0D        ; On "End"?
         BEQ C3AA99      ; Branch if so
         TAX             ; Clicked slot
         LDA $7E9D89,X   ; Nobody there?
         BMI C3AAB1      ; Exit if so
         LDA $4B         ; Clicked slot
         TAX             ; Index it
         LDA $7EAA8D-1,X ; Name color
         CMP #$20        ; Player's?
         BNE C3AAB1      ; Exit if not
         JSR C3AAB2      ; Add chosen char
         LDA $4A         ; Selection count
         CMP #$0C        ; Added 12 actors?
         BNE C3AAB1      ; Exit if not

; Fork: Put cursor on "End"
C3AAAD:  LDA #$0D        ; Row: 14th
         STA $4E         ; Set cursor's
C3AAB1:  RTS

; Fork: Handle "End"
C3AA99:  JSR C3AACA      ; Auto-fill list
         JSR fdexit      ; Queue menu exit
         JMP C30EB2      ; Sound: Click

; Fork: Handle "Reset"
C3AAA7:  INC $4E         ; Move cursor down
         BRA C3AAFD      ; Reset user's list

; Add chosen actor to player's list for final battle
C3AAB2:  TDC             ; ...
         LDA $4A         ; Slot to fill
         TAY             ; Index it
         JSR C3BFC2      ; Chosen actor
         STA $0205,Y     ; To user's list
         INC $4A         ; R-List size +1
         LDA #$28        ; Color: Gray
         STA $7EAA8C,X   ; Set L-Name's
         RTS

; Complete player's actor list for final battle
C3AACA:  LDA $4A         ; R-List size
         CMP #$0C        ; 12 actors?
         BEQ C3AAED      ; Exit if so
         TDC             ; Clear A
         TAX             ; L-List slot: 1
C3AAD2:  LDA $7EAA8D,X   ; Name color
         CMP #$20        ; Player's?
         BNE C3AAE7      ; Skip if not
;        TDC             ; Clear A
         LDA $4A         ; R-List slot
         TAY             ; Index it
         LDA $7E9D8A,X   ; L-List actor
         STA $0205,Y     ; Add to list
         INC $4A         ; R-List slot +1
C3AAE7:  INX             ; L-List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3AAD2      ; Loop if not
C3AAED:  RTS

; Clear candidate list for final battle (four unused slots)
C3AAEE:  LDX #$000F      ; List slot: 16
         LDA #$FF        ; Actor: None
.loop    STA $7E9D89,X   ; Clear slot
         DEX             ; List slot -1
         BPL .loop       ; Loop till < 0
         RTS

; Reset player's actor list for final battle
C3AAFD:  LDX #$000B      ; List slot: 12
C3AAFF:  LDA #$FF        ; Actor: None
         STA $0205,X     ; Put in slot
         LDA #$20        ; Color: User's
         STA $7EAA8D,X   ; Set name color
         DEX             ; List slot -1
         BPL C3AAFF      ; Loop till < 0
         STZ $4A         ; List size: 0
         RTS

; Draw menu for final battle
C3AB13:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C3AB49     ; C3/AB49
         JSR C30341      ; Draw window
         JSR C30E52      ; Upload window
         JSR C36A3C      ; Clear BG3 map A
         JSR C30E6E      ; Upload BG3 A+B
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C3C2F2      ; Color: User's
         LDX #C3AC84     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C369BA      ; Draw End, etc.
         JSR C3AC19      ; Draw numbers
         JSR C3AB4D      ; List candidates
         JSR C3AB89      ; Draw candidates
         JMP C30E28      ; Upload text

; Compile candidates for final battle
C3AB4D:  TDC             ; Clear A
         TAY             ; List slot: 1
         TAX             ; 1st: Terra
C3AB51:  PHX             ; Save actor
         LDA $1850,X     ; Party info
         ASL A           ; Object's off?
         BPL C3AB81      ; Skip if so
         AND #$0E        ; In a party?
         BEQ C3AB81      ; Skip if not
         STX $E7         ; Save actor
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36969,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $00,X       ; Actor in slot
         CMP #$0E        ; Guest?
         BCS C3AB81      ; Skip if so
         TYX             ; List slot
         LDA $E7         ; Actor slot
         STA $7E9D8A,X   ; Add to list
         INY             ; List slot +1
C3AB81:  PLX             ; Actor slot
         INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C3AB51      ; Loop if not
         RTS

; Draw list of candidates for final battle
C3AB89:  LDY #$3A15      ; Tilemap ptr
         STY $F5         ; Set position
         TDC             ; Clear A
         TAX             ; List slot: 1
C3AB90:  LDY $F5         ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         PHX             ; Save list slot
         TDC             ; Clear A
         LDA $7EAA8D,X   ; Name palette
         STA $29         ; Set attributes
         LDA $7E9D8A,X   ; Actor in slot
         BMI C3ABA6      ; Blank if none
         JSR C3ABF0      ; Draw name
         BRA C3ABA9      ; Skip a line
C3ABA6:  JSR C3AC0B      ; Blank slot
C3ABA9:  JSR C3ABFE      ; VRAM row +2
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3AB90      ; Loop if not
         RTS

; Draw player's actor list for final battle
C3ABB4:  JSR C3C2F2      ; Color: User's
         LDY #$3A31      ; Tilemap ptr
         STY $F5         ; Set position
         TDC             ; Clear A
         TAX             ; List slot: 1
C3ABBF:  LDY $F5         ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         PHX             ; Save list slot
         TDC             ; Clear A
         LDA $0205,X     ; Actor in slot
         BMI C3ABCE      ; Blank if none
         JSR C3ABF0      ; Draw name
         BRA C3ABD1      ; Skip a line
C3ABCE:  JSR C3AC0B      ; Blank slot
C3ABD1:  JSR C3ABFE      ; VRAM row +2
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3ABBF      ; Loop if not
         RTS

; Draw actor's name for final battle lineup
C3ABF0:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         JMP C334D2      ; Draw name

; Point two rows down in tilemap
C3ABFE:  REP #$21        ; 16-bit A; C-
         LDA $F5         ; Tilemap ptr
         ADC #$0080      ; +2 rows down
         STA $F5         ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Blank actor name slot
C3AC0B:  LDY #$0006      ; Spaces: 6
         JMP spacedr     ; Draw 6 spaces

; Draw both lists of numbers for final battle lineup
C3AC19:  LDY #$3A0F      ; Tilemap ptr
         JSR C3AC3B      ; Draw left list
         LDY #$3A2B      ; Tilemap ptr
;        BRA C3AC3B      ; Draw right list

; Draw current list of numbers for final battle lineup
C3AC3B:  STY $F5         ; Set position
         LDA #$01        ; Number: "1"
C3AC3D:  PHA             ; Save number
         JSR C304E0      ; Turn into text
         LDX $F5         ; Text position
         JSR C304B6      ; Draw 2 digits
         JSR C3ABFE      ; VRAM row +2
         PLA             ; Number
         INC A           ; Number +1
         CMP #$0D        ; Done all 12?
         BNE C3AC3D      ; Loop if not
C3AC53:  RTS

; Handle D-Pad for final battle lineup
C3AC5A:  JSR C3072D      ; Handle D-Pad
C3AC5D:  LDY #C3AC68     ; C3/AC68
         JMP C30640      ; Relocate cursor

; 71: Initialize Colosseum item menu
C3ACAA:  STZ $0201       ; Face Shadow: No
         JSR C31AE2      ; Init list vars
         JSR C37D25      ; Relocate cursor
         JSR C3AD27      ; Draw/Upload menu
         JSR C31B0E      ; Shift & OBJ & Fade
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C31368      ; Refresh screen
         LDA #$72        ; C3/ACDC
         STA $27         ; Queue: Sustain menu
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C307B0      ; Queue cursor OAM
         JMP C33541      ; BRT:1 + NMI

; 72: Sustain Colosseum item menu
C3ACDC:  JSR desc_on     ; Description: On
         STZ $2A         ; List type: Stock
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C3AC53      ; Exit if pushed
         JSR C37D22      ; Handle D-Pad
         JSR C382F1      ; Load description

; Fork: Handle A
C3ACF0:  LDA $08         ; Pushing A?
         BPL C3AD14      ; Branch if not
         JSR C3BFCB      ; Selected item
         CMP #$FF        ; None?
         BEQ C3AD0E      ; Fail if so
         STA $0205       ; Set item bet
         LDA #$75        ; C3/ADB7
         STA $27         ; Queue: Matchup
         STZ $26         ; Next: Fade-out
         JMP C30EB2      ; Sound: Click

; Fork: Invalid selection
C3AD0E:  JSR C3B66F      ; Buzzer + Mosaic

; Fork: Handle B
C3AD14:  LDA $09         ; Pushing B?
         BPL C3AC53      ; Exit if not
         LDA #$FF        ; Empty item
         STA $0205       ; Clear item bet
         JSR fdexit      ; Queue menu exit
         JMP C30EA9      ; Sound: Cursor

; Draw and upload Colosseum item menu
C3AD27:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C3AD8A     ; C3/AD8A
         JSR boxes_      ; Upload windows
         JSR bg3d_cl     ; Clear BG3 maps
         JSR C3C2F7      ; Color: Blue
         LDY #C3AD9A     ; Text pointer
         JSR C302F9      ; Draw "Colosseum"
         JSR C3C2F2      ; Color: User's
         JSR C3A73D      ; Build desc map
         LDY #C3ADA6     ; Text pointer
         JSR C302F9      ; Draw "Select..."
         JSR up_bg3      ; Upload BG3 maps
         JSR C36A19      ; Clear BG1 map B
         JSR C37E0D      ; Draw inventory
         JSR C382F1      ; Load description
         JMP C30E28      ; Upload BG1 A+B

; 75: Initialize Colosseum matchup menu
C3ADB7:  JSR C3352F      ; Reset/Stop stuff
         STZ $43         ; Disable HDMA
;        JSR C33A87      ; Load skin visuals
;        JSR C36915      ; Get party info
         LDA #$02        ; Gradient set: 2
         JSL $D4CA1D     ; Create gradient
         JSR C369DC      ; Queue Win1 HDMA
         JSR C36A66      ; Load GFX/pal/prize
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDY #C3B332     ; C3/B332
         JSR C305FE      ; Load navig data
         JSR C3B32C      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDY #C3B2F3     ; C3/B2F3
         JSR qanim1      ; Queue "VS" OAM
         JSR C318D1      ; Set to shift text
         JSR C3AE34      ; Draw menu; members
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C33F99      ; Apply user font
         LDY #C3B2A5     ; C3/B2A5
         JSR qanim1      ; Queue challenger fn
         LDA #$76        ; C3/AE0F
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
;        JSR C36904      ; Reset BGs' X/Y
         JSR C30EFD      ; Queue enemy upload
         JSR C33541      ; BRT:1 + NMI
         JMP C30F39      ; Queue text upload

; 76: Sustain Colosseum matchup menu
C3AE0F:  JSR C30F39      ; Queue text upload
         JSR C3B329      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3AEA6      ; Exit if not
         JSR C3B2EC      ; Actor in slot
         BMI C3AE2D      ; Fail if nobody
         STA $0208       ; Set challenger
         JSR fdexit      ; Queue menu exit
         JMP C30EB2      ; Sound: Click
C3AE2D:  JMP C3B66F      ; Buzzer + Mosaic

; Draw Colosseum matchup menu and create members
C3AE34:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C3B33F     ; C3/B33F
         JSR boxes_      ; Upload windows
         JSR C36A3C      ; Clear BG3 map A
         JSR C3C2F2      ; Color: User's
         JSR C3B17D      ; Create member 1
         JSR C3B197      ; Create member 2
         JSR C3B1B1      ; Create member 3
         JSR C3B1CB      ; Create member 4
         LDY #C3B40F     ; Text pointer
         JSR C302F9      ; Draw "Select..."
         JSR C3B28D      ; Draw enemy name
         JSR C3B24D      ; Draw item bet
         JSR C3B255      ; Draw prize
         JSR C30E6E      ; Upload BG3 A+B
         LDY #$5000      ; $5000
         STY $2116       ; Set VRAM ptr
         JSR C3B10A      ; Blank BG1 tile 1
         JSR C36A15      ; Clear BG1 map A
         JSR C3AE93      ; Handle Striker
         LDA $0201       ; Facing Shadow?
         BNE C3AE8D      ; Branch if so
         JSR C3AF00      ; Draw monster
         BRA C3AE8_      ; Upload BG1 A+B

; Fork: Fighting Shadow
C3AE8D:  JSR C3AEA7      ; Do name/sprite
C3AE8_:  JMP C30E28      ; Upload BG1 A+B

; Check if betting Striker
C3AE93:  LDA $0205       ; Item bet
         CMP #$29        ; Striker?
         BNE C3AEA6      ; Exit if not
         LDA $1EBD       ; Shadow at arena?
         BPL C3AEA6      ; Exit if not
         LDA #$01        ; Facing Shadow: Y
         STA $0201       ; Set arena's mode
C3AEA6:  RTS

; Create Shadow's name and sprite for Colosseum
C3AEA7:  JSR C3AED9      ; Draw "Shadow"
         LDA #$02        ; For C3/7B8F...
         TSB $47         ; See C3/B2BB...
         LDY #C37A5F     ; C3/7A5F
         JSR qanim2      ; Queue OAM fn
         LDA #$01        ; OAM mode: 1
         STA $7E3649,X   ; Set sprite's
         LDA $7E364A,X   ; Sprite flags
         ORA #$02        ; Add H-Flip
         STA $7E364A,X   ; Save changes
         TXY             ; Queue index
         PEA $6838       ; Pos: 56, 104
         TDC             ; Clear A
         LDA #$03        ; Sprite set: 3
         JMP C3B211      ; Set pos/OAM ptr

; Draw Shadow's name at Colosseum
C3AED9:  LDX #$001E      ; 1st: Guest 2
C3AEDB:  REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor in slot
         CMP #$03        ; Shadow?
         BEQ C3AEF8      ; Retain if so
         DEX             ; Actor index -1
         DEX             ; Actor index -1
         BPL C3AEDB      ; Loop till < 0
         STP             ; Freeze game...
C3AEF8:  STY $67         ; Save actor index
         LDY #$7C11      ; Text position
         JMP C334CF      ; Draw actor name

; Build tilemap for Colosseum enemy
C3AF00:  LDX $91         ; Tilemap ptr
         STX $ED         ; Set dst LBs
         LDA $99         ; Monster size
         CMP #$08        ; 8x8 tiles?
         BEQ C3AF16      ; Branch if so
         LDX #$0010      ; Tiles: 16
         STX $F1         ; Set height
         STX $E0         ; Set width
         BRA C3AF1D      ; Skip 3 lines
C3AF16:  LDX #$0008      ; Tiles: 8
         STX $F1         ; Set height
         STX $E0         ; Set width
C3AF1D:  LDA #$7E        ; Bank: 7E
         STA $EF         ; Set dst HB
         REP #$20        ; 16-bit A
         LDA #$2C01      ; Tile 1, pal 3
         STA $E7         ; Priority: Yes
C3AF28:  LDX $E0         ; Width in tiles
         LDY $00         ; Map index: 0
C3AF2C:  LDA $E7         ; Tile attribs
         STA [$ED],Y     ; Put in tilemap
         INY             ; Map index +1
         INY             ; Map index +1
         INC $E7         ; Tile number +1
         DEX             ; One less column
         BNE C3AF2C      ; Loop till last
         LDA $ED         ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $ED         ; Save changes
         DEC $F1         ; One less row
         BNE C3AF28      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load prize and enemy data for Colosseum matchup
C3AF46:  JSR C3B22C      ; Set enemy, prize
         LDY #$5010      ; $5010
         STY $2116       ; Set VRAM ptr
         LDA $0206       ; Enemy number
         XBA             ; Put in B
         LDA #$05        ; Enemy data size
         JSR mul8        ; Enemy x size
         TAX             ; Index product
         LDA $D27000,X   ; GFX ptr/8 LSBs
         STA $E7         ; Save in RAM
         LDA $D27001,X   ; Ptr MSBs; flag
         STA $E8         ; Save in RAM
         LDA $D27002,X   ; Pal/Mold info
         STA $F2         ; Save in RAM
         LDA $D27003,X   ; Palette LSBs
         STA $F1         ; Save in RAM
         LDA $D27004,X   ; Mold index LSBs
         STA $E9         ; Save in RAM

; Fork: Relocate color depth flag
C3AF7D:  LDA $E8         ; 8-color palette?
         BMI C3AF85      ; Branch if so
         STZ $FF         ; Colors: 16
         BRA C3AF8D      ; Skip other case
C3AF85:  LDA #$01        ; Colors: 8
         STA $FF         ; Set color depth
         LDA #$80        ; 8-color flag
         TRB $E8         ; Clear original

; Fork: Compute enemy graphics address ($E97000+8X)
C3AF8D:  LDY $E7         ; GFX ptr / 8
         LDA #$08        ; Multiplier
         JSR mul16       ; GFX ptr x 8
;        LDA $2136       ; Product HB
         CLC             ; Prepare ADC
         ADC #$E9        ; Add base adr
         STA $F7         ; Set address HB
         REP #$21        ; 16-bit A; C-
         TXA             ; Product LBS
         ADC #$7000      ; Add base adr
         STA $F5         ; Set address LBs
         SEP #$20        ; 8-bit A
         BCC .skip       ; If no overflow
         INC $F7         ; Address HB +1
.skip    LDX $00         ; GFX index: 0

; Fork: Set address pointer and size for 8x8 mold data
C3AFB9:  LDA $F2         ; 16x16 image?
         BMI C3AFC8      ; Branch if so
         LDY #$A820      ; D2/A820
         STY $E3         ; Set address ptr
         LDA #$08        ; 8-tile rows: 8
         BRA C3AFCF      ; Set data size

; Fork: Set address pointer and size for 16x16 mold data
C3AFC8:  LDY #$A822      ; D2/A822
         STY $E3         ; Set address ptr
         LDA #$20        ; 8-tile rows: 32
C3AFCF:  STA $E6         ; Set rows left
         STA $99         ; Set enemy size
         LDA #$D2        ; Bank: D2
         STA $E5         ; Set pointer HB

; Fork: Define mold index's high byte
C3AFD7:  LDA $F2         ; Monster flags
         AND #$40        ; Mold index MSB
         ASL A           ; Put in bit 7
         ASL A           ; Put in Carry
         ROL A           ; Put in bit 0
         STA $EA         ; Set index HB

; Fork: Load address to 8x8 enemy's mold ($D2A824+8X)
C3AFE0:  LDA $F2         ; 16x16 image?
         BMI C3AFED      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $E9         ; Mold index
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         BRA C3AFF6      ; Set address

; Fork: Load address to 16x16 enemy's mold ($D2AC24+32X)
C3AFED:  REP #$20        ; 16-bit A
         LDA $E9         ; Mold index
         JSR x32         ; x32
C3AFF6:  CLC             ; Prepare ADC
         ADC [$E3]       ; Add base adr
         STA $E0         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$D2        ; Bank: D2
         STA $E2         ; Set src HB

; Fork: Load 8-tile row, blank tiles excluded from mold
C3B001:  LDY #$0008      ; Columns: 8
         PHX             ; Save GFX index
         TDC             ; Clear A
         LDA $E6         ; Rows left
         TAX             ; Index it
         LDA [$E0]       ; Mold row flags
         STA $7E9D88,X   ; For centering
         PLX             ; GFX index
C3B010:  CLC             ; Prepare ROL
         PHY             ; Save column
         ROL A           ; Blank tile here?
         PHA             ; Save mold flags
         BCC C3B01B      ; Branch if blank
         JSR C3B11E      ; Load tile's GFX
         BRA C3B01E      ; Skip a line
C3B01B:  JSR C3B10A      ; Make blank tile
C3B01E:  PLA             ; Mold row flags
         PLY             ; Columns left
         DEY             ; One less left
         BNE C3B010      ; Loop till last

; Fork: Handle next 8-tile row
C3B023:  REP #$20        ; 16-bit A
         INC $E0         ; Mold data adr +1
         SEP #$20        ; 8-bit A
         DEC $E6         ; One less row
         BNE C3B001      ; Loop till last

; Fork: Set position and load colors
C3B02D:  JSR C3B033      ; Set tilemap ptr
         JMP C3B15A      ; Load enemy pal

; Position Colosseum enemy based on size
C3B033:  STZ $E0         ; Blank rows: 0
         STZ $E4         ; Rel pos LB: 0
         STZ $E5         ; Rel pos HB: 0
         STZ $E3         ; Clear filled cols
         LDX $00         ; 1st: Bottom row
         LDA $99         ; Monster size
         CMP #$08        ; 8x8 tiles?
         BNE C3B079      ; Branch if not

; Fork: Count blank rows, identify filled columns (8x8)
C3B043:  LDA $7E9D89,X   ; Blank row here?
         BNE C3B050      ; Branch if not
         INC $E0         ; Blank rows +1
         INX             ; Point 1 row up
         CMP #$08        ; Bogus...
         BNE C3B043      ; Test next row
C3B050:  LDX $00         ; 1st: Bottom row
C3B052:  LDA $7E9D89,X   ; Row's filled cols
         ORA $E3         ; Add prior rows'
         STA $E3         ; Save merged rows
         INX             ; Point 1 row up
         CPX #$0008      ; Done all 8 rows?
         BNE C3B052      ; Loop if not

; Fork: Position 8x8 enemy based on empty columns
C3B060:  ROR $E3         ; Empty column here?
         BCS C3B068      ; Branch if not
         INC $E4         ; Relative pos +1
         BRA C3B060      ; Test next column
C3B068:  LSR $E4         ; If odd-numbered:
         ASL $E4         ; Relative pos -1
         REP #$21        ; 16-bit A; C-
         LDA $E4         ; Relative position
         ADC #$3A51      ; X+4, Y+8 tiles
         STA $E7         ; Save tilemap ptr
         BRA C3B0B7      ; Adjust Y position

; Fork: Count blank rows, identify R-Half's filled columns (16x16)
C3B079:  LDA $7E9D89,X   ; Row's right half
         ORA $7E9D8A,X   ; L-Half empty too?
         BNE C3B08C      ; Branch if not
         INC $E0         ; Blank rows +1
         INX             ; 8-tile index +1
         INX             ; 8-tile index +1
         CPX #$0020      ; Done all 16 rows?
         BNE C3B079      ; Loop if not
C3B08C:  LDX $00         ; 1st: Bottom row
C3B08E:  LDA $7E9D89,X   ; R-Half filled cols
         ORA $E3         ; Add prior rows'
         STA $E3         ; Save merged rows
         INX             ; 8-tile index +1
         INX             ; 8-tile index +1
         CPX #$0020      ; Done all 16 rows?
         BNE C3B08E      ; Loop if not

; Fork: Position 16x16 enemy based on empty columns
C3B09D:  ROR $E3         ; Empty column?
         BCS C3B0A5      ; Branch if not
         INC $E4         ; Relative pos +1
         BRA C3B09D      ; Test next column
C3B0A5:  LSR $E4         ; If odd-numbered:
         ASL $E4         ; Relative pos -1
         REP #$21        ; 16-bit A; C-
         LDA $E4         ; Relative position
         ADC #$3849      ; Add base address
         STA $E7         ; Save tilemap ptr

; Fork: Adjust Y position based on enemy and blank rows
C3B0B7:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $0206       ; Enemy number
         TAX             ; Index it
         LDA $ECE800,X   ; Modifier index
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JMP (C3B0C9,X)  ; Shift enemy

; Jump table for the above
C3B0C9:  dw C3B0D3       ; Shift up by 3
         dw C3B0F8       ; Shift down by $E0
         dw C3B0E2       ; Shift down by $E0 - 1
         dw C3B0EA       ; Shift down by $E0 + 1
         dw C3B0EE       ; Shift down by $E0 - 3

; Shift enemy up by 3 tiles
C3B0D3:  STZ $E0         ; Blank rows: 0
         REP #$20        ; 16-bit A
         LDA $E7         ; Tilemap ptr
         SEC             ; Prepare SBC
         SBC #$00C0      ; Go 3 rows up
         STA $91         ; Save map ptr
         SEP #$20        ; 8-bit A
         RTS

; Shift enemy down by $E0 - 1
C3B0E2:  DEC $E0         ; Blank rows -1
         BPL C3B0E8      ; Branch if 0+
         STZ $E0         ; Blank rows: 0
C3B0E8:  BRA C3B0F8      ; Shift enemy

; Shift enemy down by $E0 + 1
C3B0EA:  INC $E0         ; Blank rows +1
         BRA C3B0F8      ; Shift enemy

; Shift enemy down by $E0 - 3
C3B0EE:  DEC $E0         ; Blank rows -1
         DEC $E0         ; Blank rows -1
         DEC $E0         ; Blank rows -1
         BPL C3B0F8      ; Branch if 0+
         STZ $E0         ; Blank rows: 0

; Shift enemy down by $E0
C3B0F8:  TDC             ; ...
         LDA $E0         ; Blank rows
         REP #$21        ; 16-bit A; C-
         JSR x64         ; x64
         ADC $E7         ; Add map ptr
         STA $91         ; Save map ptr
         SEP #$20        ; 8-bit A
         RTS

; Create a blank tile at current location in VRAM
C3B10A:  REP #$20        ; 16-bit A
         LDA #$0010      ; Loop counter
C3B113:  STZ $2118       ; 8 px, 2 planes
         DEC A           ; Counter -1
         BNE C3B113      ; Loop till 0
         SEP #$20        ; 8-bit A
         RTS

; Upload current tile from monster's tileset
C3B11E:  TXY             ; GFX index
         LDA $FF         ; Has 8 colors?
         BNE C3B129      ; Branch if so
         LDX #$0010      ; Bytes: 32
         BRA C3B145      ; Load tile GFX

; Fork: Load 8-color tile, encode as 4bpp
C3B129:  LDX #$0008      ; Bytes: 16
         JSR C3B145      ; Load rows' LSBs
         LDX #$0008      ; Rows left: 8
         TDC             ; Clear A
C3B136:  LDA [$F5],Y     ; GFX row's MSBs
         REP #$20        ; 16-bit A
         STA $2118       ; Save in VRAM
         SEP #$20        ; 8-bit A
         INY             ; GFX index +1
         DEX             ; One less row
         BNE C3B136      ; Loop till last
         TYX             ; GFX index
         RTS

; Fork: Upload specified number of words
C3B145:  REP #$20        ; 16-bit A
C3B14A:  LDA [$F5],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; GFX index +1
         INY             ; GFX index +1
         DEX             ; Counter -1
         BNE C3B14A      ; Loop till 0
         SEP #$20        ; 8-bit A
         TYX             ; GFX index
         RTS

; Load monster's palette
C3B15A:  REP #$20        ; 16-bit A
         LDA $F1         ; Palette index
         AND #$03FF      ; Clear flags
         JSR x16         ; x16
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY #$30A9      ; 7E/30A9
         STY $2181       ; Set WRAM LBs
         LDY #$0020      ; Colors: 16
C3B171:  LDA $D27820,X   ; Color data
         STA $2180       ; To BG pal 3
         INX             ; ROM index +1
         DEY             ; One less byte
         BNE C3B171      ; Loop till last
C3B17C:  RTS

; Create Colosseum member 1
C3B17D:  LDY $6D         ; Actor's address
         BEQ C3B17C      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E4F      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDX #$A820      ; OBJ pos: 32, 168
         LDA $69         ; Actor's slot
         BRA C3B1F3      ; Init sprite

; Create Colosseum member 2
C3B197:  LDY $6F         ; Actor's address
         BEQ C3B17C      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E5D      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDX #$A858      ; OBJ pos: 88, 168
         LDA $6A         ; Actor
         BRA C3B1F3      ; Init sprite

; Create Colosseum member 3
C3B1B1:  LDY $71         ; Actor's address
         BEQ C3B17C      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E6B      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDX #$A890      ; OBJ pos: 144, 168
         LDA $6B         ; Actor's slot
         BRA C3B1F3      ; Init sprite

; Create Colosseum member 4
C3B1CB:  LDY $73         ; Actor's address
         BEQ C3B17C      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E79      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDX #$A8C8      ; OBJ pos: 200, 168
         LDA $6C         ; Actor's slot

; Create Colosseum actor sprite, excluding enemy Shadow
C3B1F3:  PHX             ; Save position
         ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $14,X       ; Status
         AND #$20        ; Imp?
         BEQ C3B20A      ; Branch if not
         LDA #$0F        ; Use Imp set
         BRA C3B211      ; Skip a line
C3B20A:  LDA $01,X       ; Sprite set
C3B211:  JSR C378FA      ; Set anim ptr
         TYX             ; Queue index
         PLY             ; Position
         JSR objpos      ; Set sprite's
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Draw Colosseum member's name, queue sprite function
C3B1E5:  JSR C334CF      ; Draw actor name
         LDY #C37A5F     ; C3/7A5F
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         RTS

; Load opponent and prize data for item bet
C3B22C:  TDC             ; Clear A
         LDA $0205       ; Item bet
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $DFB600,X   ; Opponent
         STA $0206       ; Save in RAM
         LDA $DFB602,X   ; Prize
         STA $0207       ; Save in RAM
         LDA $DFB603,X   ; Hide Prize flag
         STA $0209       ; Save in RAM
         RTS             ; ^ Read below

; Draw Colosseum bet
C3B24D:  LDA $0205       ; Item bet
         LDY #$792B      ; Text position
         BRA C3B263      ; Draw item name

; Draw Colosseum prize
C3B255:  LDA $0209       ; Hide prize?
         BNE C3B286      ; Use "???" if so
         LDA $0207       ; Prize
         LDY #$790D      ; Tilemap ptr
C3B263:  PHA             ; Save item
         JSR C33519      ; Set position
         PLA             ; Item
         JSR C3C068      ; Load name
         JMP C37FD9      ; Draw name

; Fork: Draw question marks
C3B286:  LDY #C3B427     ; Text pointer
         JMP C302F9      ; Draw string

; Draw monster's name for Colosseum
C3B28D:  LDY #$7C4F      ; Tilemap ptr
         JSR C33519      ; Set position
         JSR C35409      ; Define source
         LDA $0206       ; Opponent
         JSR C38467      ; Load name
         JMP C37FD_      ; Draw name

; Update Colosseum challenger's name and sprite
C3B2A5:  TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         JSR C32D0B      ; Actor's address
         BEQ C3B2DF      ; Blank if nobody
         STY $67         ; Memorize it
         LDY #$7C75      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$02        ; Temp sprite: Y
         TSB $47         ; Set menu flag
         LDY #C37B42     ; C3/7B42
         JSR qanim2      ; Queue OAM fn
         LDA #$01        ; Anim mode: 1
         STA $7E3649,X   ; Set sprite's
         TXY             ; Queue index
         JSR C3B2EC      ; Actor's slot
         LDX #$68B8      ; Pos: 184, 104
         JSR C3B1F3      ; Init sprite
         BRA C3B2E2      ; Skip a line
C3B2DF:  JSR C3B2E5      ; Blank name
C3B2E2:  SEC             ; Set to requeue
         RTS

; Blank challenger's name
C3B2E5:  LDY #C3B406     ; Text pointer
         JMP C302F9      ; Draw 6 spaces

; Get party actor indicated by cursor
C3B2EC:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $69,X       ; Actor slot
         RTS

; Update "VS" symbol from Colosseum
C3B2F3:  BNE C3B31E      ; If mode 1

; Mode 0: Initialize sprite
C3B2FB:  INC $3649,X     ; Mode +1
         LDA #$D8        ; Anim ptr HB
         LDY #$EC87      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDY #$6070      ; Pos: 112, 96
         JSR objpos      ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3B31E:  JMP oamsec      ; Set OAM; requeue

; Handle D-Pad for Colosseum matchup menu
C3B329:  JSR C3072D      ; Handle D-Pad
C3B32C:  LDY #C3B337     ; C3/B337
         JMP C30640      ; Relocate cursor

; Load arena graphics, tilemap, and colors
C3B34B:  REP #$20        ; 16-bit A
         LDA $E7168C     ; E8/0C49
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $E7168E     ; Src HB: E8
         JSR C3B3F2      ; Unpack GFX A
         LDY #$6800      ; $6800
         STY $2116       ; Set VRAM ptr
         LDX $00         ; 1st: 7E/B68D
         LDY #$1000      ; End: 7E/C68C
         JSR C3B3C6      ; Upload GFX A

; Fork: Unpack and upload graphics for upper half
C3B36E:  REP #$20        ; 16-bit A
         LDA $E71692     ; E8/1841
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $E71694     ; Src HB: E8
         JSR C3B3F2      ; Unpack GFX B
         LDY #$7000      ; $7000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; 1st: 7E/B68D
         LDY #$1000      ; End: 7E/C68C
         JSR C3B3C6      ; Upload GFX B

; Fork: Unpack battle tilemap, convert to menu format
C3B391:  REP #$20        ; 16-bit A
         LDA $E7187A     ; E7/652B
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$E7        ; Src HB: E7
         JSR C3B3F2      ; Unpack map
         JSR C3B3D8      ; Convert map

; Fork: Load colors
C3B3A5:  LDX #$005F      ; Colors: 48
C3B3BA:  LDA $E70AB0,X   ; Color data
         STA $7E30C9,X   ; To BG pal 4/5/6
         DEX             ; Index -1
         BPL C3B3BA      ; Loop till < 0
         RTS

; Upload current graphics set for arena background
C3B3C6:  STY $E7         ; Set src end
         REP #$20        ; 16-bit A
C3B3C8:  LDA $7EB68D,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX $E7         ; Past range?
         BNE C3B3C8      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Convert and relocate decompressed arena tilemap
C3B3D8:  REP #$20        ; 16-bit A
         LDX #$057E      ; Base index
C3B3DC:  LDA $7EB68D,X   ; Attributes
         SEC             ; Prepare SBC
         SBC #$0380      ; Tile num -896
         STA $7E5949,X   ; Put in BG2a
         DEX             ; Index -1
         DEX             ; Index -1
         BPL C3B3DC      ; Loop till < 0
         SEP #$20        ; 8-bit A
         RTS

; Decompress data for arena background
C3B3F2:  STY $F3         ; Set src LBs
         STA $F5         ; Set src HB
         LDY #$B68D      ; 7E/B68D
         STY $F6         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $F8         ; Set dst HB
         JSL $C2FF6D     ; Unpack data
         RTS

; 24: Initialize shop menu
C3B466:  JSR C3352F      ; Reset/Stop stuff
         JSR C36904      ; Reset BGs' X/Y
         JSR C36A08      ; Set Win1 bounds
;        LDA #$03        ; 64x64 at $0000
;        STA $2107       ; Set BG1 map loc
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         STZ $4A         ; Sell list scroll: 0
         JSR C3B886      ; Load navig data
         JSR C3B88F      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C3B8C4      ; Draw menu; desc
         JSR C37E2B      ; Set to shift text
         LDY #C3C037     ; C3/C037
         STY $4352       ; Redirect BG3's
         LDA #$25        ; C3/B49B
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 25: Sustain main shop menu
C3B49B:  JSR C3B88C      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3B4AA      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JMP C3B792      ; Handle choice

; Fork: Handle B
C3B4AA:  LDA $09         ; Pushing B?
         BPL C3B538      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C3B4B3: ;STZ $0205       ; Never read...
         JMP fdexit      ; Queue menu exit

; 26: Handle buy item list
C3B4BD:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30F39      ; Queue text upload
         JSR C3B8A6      ; Handle D-Pad
         JSR C3BC84      ; Draw qty owned
         JSR C3BCA8      ; Draw qty worn

; Fork: Handle B
C3B4CD:  LDA $09         ; Pushing B?
         BPL C3B4D9      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JMP C3B760      ; Exit submenu

; Fork: Handle A
C3B4D9:  LDA $08         ; Pushing A?
         BPL C3B538      ; Exit if not
         JSR C3B82F      ; Set buy limit
         JMP C3B7E6      ; Test GP, stock

; Set description to be displayed and to ignore joypad
C3B4E6:  LDA #$20        ; D-Pad: Ignore
         TSB $45         ; Set desc flag
desc_on: LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         RTS

; Load item description for Buy menu
C3B4EF:  JSR C38308      ; Set desc ptrs
         JMP C35730      ; Load description

; Load item description for Sell menu
C3B4F8:  JSR C38308      ; Set desc ptrs
         JSR C3BFCB      ; Selected item
         JMP C35738      ; Load description

; 27: Handle buy order menu
C3B505:  JSR C3B4E6      ; Set desc flags
         JSR C3B4EF      ; Load description
         JSR C3BB53      ; Get order value
         JSR C3BBAE      ; Draw size, value

; Fork: Buy quantity +1
C3B511:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3B539      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Buy quantity
         CMP $6A         ; At capacity?
         BEQ C3B59E      ; Abort if so
         INC $28         ; Quantity +1
         JSR C3BB53      ; Get new cost
         REP #$20        ; 16-bit A
         LDA $1860       ; Gold LBs
         CMP $F1         ; C- if < cost's
         SEP #$20        ; 8-bit A
         LDA $1862       ; Gold HB
         SBC $F3         ; So, GP < cost?
         BCS C3B538      ; Exit if not
         DEC $28         ; Quantity -1
C3B538:  RTS

; Fork: Buy quantity -1
C3B539:  LSR A           ; Pushing left?
         BCC C3B54A      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Buy quantity
         DEC A           ; One?
         BEQ C3B59E      ; Abort if so
         DEC $28         ; Quantity -1

; Fork: Buy quantity +10
C3B54A:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3B583      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA #$0A        ; Quantity: 10
         CLC             ; Prepare ADC
         ADC $28         ; Add order size
         CMP $6A         ; At capacity?
         BEQ C3B55E      ; Retain if so
         BCS C3B57F      ; Abort if over
C3B55E:  STA $28         ; Set order size
         JSR C3BB53      ; Get new cost
         REP #$20        ; 16-bit A
         LDA $1860       ; Gold LBs
         CMP $F1         ; C- if < cost's
         SEP #$20        ; 8-bit A
         LDA $1862       ; Gold HB
         SBC $F3         ; So, GP < cost?
         BCS C3B57B      ; Exit if not
         LDA $28         ; Buy quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         STA $28         ; Save changes
C3B57B:  RTS

; Fork: Leave quantity unchanged...
C3B57F:  LDA $28         ; Buy quantity
         BRA C3B55E      ; Test cost

; Fork: Buy quantity -10
C3B583:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3B59E      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Buy quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         BMI C3B59A      ; Use 1 if < 0
         BEQ C3B59E      ; Abort if 0
         STA $28         ; Save changes
C3B599:  RTS

; Fork: Set buy quantity to 1
C3B59A:  LDA #$01        ; Quantity: 1
         STA $28         ; Set order size

; Fork: Handle B
C3B59E:  LDA $09         ; Pushing B?
         BPL C3B5AA      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JMP C3B7B3      ; Exit submenu

; Fork: Handle A
C3B5AA:  LDA $08         ; Pushing A?
         BPL C3B599      ; Exit if not
         JSR C30ECE      ; Sound: Cash
         JSR C3BFC2      ; Bought item
         LDY $00         ; Item slot: 1
C3B5BC:  CMP $1869,Y     ; Slot holds it?
         BEQ C3B5E1      ; Qty +1 if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C3B5BC      ; Loop if not
         LDY $00         ; Item slot: 1
C3B5C9:  LDA $1869,Y     ; Item in slot
         INC A           ; None?
         BEQ C3B5D3      ; Overwrite if so
         INY             ; Item slot +1
         BRA C3B5C9      ; Try next slot

; Fork: Put bought item in empty slot
C3B5D3:  LDA $28         ; Quantity bought
         STA $1969,Y     ; Assign to slot
         LDA $7E9D89,X   ; Bought item
         STA $1869,Y     ; Assign to slot
         BRA C3B5EA      ; Reduce GP, etc.

; Fork: Add quantity bought to stock
C3B5E1:  LDA $28         ; Quantity bought
         CLC             ; Prepare ADC
         ADC $1969,Y     ; Add qty owned
         STA $1969,Y     ; Set qty owned

; Fork: Reduce party's GP, leave submenu
C3B5EA:  JSR C3BB53      ; Get order value
         SEC             ; Prepare SBC
         LDA $1860       ; Gold LB
         SBC $F1         ; Deduct cost's
         STA $1860       ; Save changes
         REP #$20        ; 16-bit A
         LDA $1861       ; Gold HBs
         SBC $F2         ; Deduct cost's
         STA $1861       ; Save changes
         SEP #$20        ; 8-bit A
         JSR C332CE      ; Cap GP
         LDY #C3C3BD     ; Text pointer
         JSR C302F9      ; Draw "Bye!"
         JMP C3B87D      ; Set to exit

; 28: Return to Buy menu after delay
C3B60E:  LDA $20         ; Delay expired?
         BNE C3B615      ; Exit if not
         JMP C3B7B3      ; Leave submenu
C3B615:  RTS

; 29: Handle sell item list
C3B616:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         TDC             ; Clear A
         STA $2A         ; List type: Stock
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C3B615      ; Exit if pushed
         JSR C37D22      ; Handle D-Pad

; Fork: Handle B
C3B628:  LDA $09         ; Pushing B?
         BPL C3B634      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JMP C3B760      ; Exit submenu

; Fork: Handle A
C3B634:  LDA $08         ; Pushing A?
         BPL C3B615      ; Exit if not
         JSR C3BFCB      ; Selected item
         INC A           ; Empty slot?
         BEQ C3B66F      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C36A15      ; Blank item list
         JSR C30EFD      ; Set to upload it
         JSR C31368      ; Upload it now
         LDA #$2A        ; C3/B676
         STA $26         ; Next: Order menu
         LDX #$3408      ; Pos: 8, 52
         STX $55         ; Set cursor's
         JSR C3BAA5      ; Draw blue text
         JSR C3BAD3      ; Draw item info
         LDY #C3C396     ; Text pointer
         JSR C302F9      ; Draw "How many?"
         JMP C3B86D      ; Switch screen

; Play buzzer, pixelate screen
C3B66F:  JSR C30EC0      ; Play buzzer
         JMP C3305D      ; Pixelate screen

; 2A: Handle sell order menu
C3B676:  JSR C3B4E6      ; Set desc flags
         JSR C3B4F8      ; Load description
         JSR C3BB65      ; Get order value
         JSR C3BBB7      ; Draw qty, offer

; Fork: Sell quantity +1
C3B682:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3B695      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Sell quantity
         CMP $64         ; Can sell more?
         BEQ C3B6E0      ; Abort if not
         INC $28         ; Quantity +1
         BRA C3B6E0      ; Handle B

; Fork: Sell quantity -1
C3B695:  LSR A           ; Pushing left?
         BCC C3B6A6      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Sell quantity
         DEC A           ; One?
         BEQ C3B6E0      ; Abort if so
         DEC $28         ; Quantity -1

; Fork: Sell quantity +10
C3B6A6:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3B6C4      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA #$0A        ; Quantity: 10
         CLC             ; Prepare ADC
         ADC $28         ; Add order size
         CMP $64         ; Owning enough?
         BCS C3B6BE      ; Limit if not
         STA $28         ; Set order size
         BRA C3B6E0      ; Handle B

; Fork: Limit sell quantity
C3B6BE:  LDA $64         ; Quantity owned
         STA $28         ; Set order size
         BRA C3B6E0      ; Handle B

; Fork: Sell quantity -10
C3B6C4:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3B6E0      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Sell quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         BMI C3B6DC      ; Use 1 if < 0
         BEQ C3B6E0      ; Abort if 0
         STA $28         ; Save changes
         BRA C3B6E0      ; Handle B

; Fork: Set sell quantity to 1
C3B6DC:  LDA #$01        ; Quantity: 1
         STA $28         ; Set order size

; Fork: Handle B
C3B6E0:  LDA $09         ; Pushing B?
         BPL C3B6FB      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDX $00         ; Clear X
         STX $39         ; BG2 X-Pos: 0
         STX $3B         ; BG2 Y-Pos: 0
         JSR C3B95A      ; Clean up BG3
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         JMP C3B7CF      ; Exit submenu

; Fork: Handle A
C3B6FB:  LDA $08         ; Pushing A?
         BPL C3B75F      ; Exit if not
         JSR C30ECE      ; Sound: Cash
         JSR C3BB65      ; Get order value
         REP #$21        ; 16-bit A; C-
         LDA $1860       ; Gold LBs
         ADC $F1         ; Add cost's
         STA $1860       ; Save changes
         SEP #$20        ; 8-bit A
         LDA $1862       ; Gold HB
         ADC $F3         ; Add cost's + C
         STA $1862       ; Save changes
         LDA $64         ; Quantity owned
         CMP $28         ; Sold all of it?
         BEQ C3B734      ; Branch if so
         JSR C3BFCB      ; Define Y
         LDA $1969,Y     ; Quantity owned
         SEC             ; Prepare SBC
         SBC $28         ; Deduct qty sold
         STA $1969,Y     ; Save changes
         BRA C3B740      ; Skip 5 lines

; Fork: Clear item slot, leave submenu
C3B734:  JSR C3BFCB      ; Define Y
         LDA #$FF        ; Empty item
         STA $1869,Y     ; Put in slot
         TDC             ; Quantity: 0
         STA $1969,Y     ; Assign to slot
C3B740:  JSR C332CE      ; Cap GP
         LDA #$2B        ; C3/B752
         STA $26         ; Next: Exit
         LDA #$20        ; Frames: 32
         STA $20         ; Set delay
         LDY #C3C3BD     ; Text pointer
         JMP C302F9      ; Draw "Bye!"

; 2B: Return to Sell menu after delay
C3B752:  LDX $20         ; Delay expired?
         BNE C3B75F      ; Exit if not
         STX $39         ; BG2 X-Pos: 0
         STX $3B         ; BG2 Y-Pos: 0
         BRA C3B7CF      ; Exit submenu
C3B75F:  RTS

; Return to main shop menu
C3B760:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         STZ $47         ; Actors: Off
         JSR C3B886      ; Load navig data
         JSR C3B88F      ; Relocate cursor
         JSR C30EFD      ; Set to upload BG1
         JSR C3B94E      ; Clear BG1 maps
         JSR C31368      ; Refresh screen
         JSR C30F39      ; Queue BG3 upload
         JSR C3B95A      ; Clean up BG3
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         LDY #C3C36F     ; Text pointer
         JSR C302F9      ; Draw greeting
         LDY $00         ; Clear Y
         STY $39         ; Reset BG2 X-Pos
         STY $3B         ; Reset BG2 Y-Pos
         LDA #$25        ; C3/B49B
         STA $26         ; Next: Shop menu
         RTS

; Handle selected option in shop menu
C3B792:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3B79A,X)  ; Handle option

; Jump table
C3B79A:  dw C3B7A3       ; BUY
         dw C3B7C7       ; SELL
         dw C3B7A0       ; EXIT

; Exit shop
C3B7A0:  JMP C3B4B3      ; Queue menu exit

; Initialize Buy menu
C3B7A3:  LDY #C3B8AF     ; C3/B8AF
         JSR C305FE      ; Load navig data
         JSR C3B8A9      ; Relocate cursor
         LDA #$08        ; Arm waving: On
         TRB $47         ; Never off...
         JSR C3C09A      ; Create actors
         JSR C3C23B      ; Create signs
C3B7B3:  LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         LDY $00         ; Y: 0
         STY $3B         ; Set BG2 Y-Pos
         LDA #$26        ; C3/B4BD
         STA $26         ; Next: Buy list
         JSR C3B986      ; Draw all text
         JMP C3BCFD      ; Build sign list

; Initialize Sell menu
C3B7C7:  JSR C30F39      ; Queue BG3 upload
         JSR C3BBE0      ; Cursor/list/bar
         BRA C3B7D2      ; Skip a line

; Return to Sell menu
C3B7CF:  JSR C3BC02      ; Draw list; bar
C3B7D2:  JSR C3B95A      ; Draw title, GP
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         LDY #C3C3A2     ; Text pointer
         JSR C302F9      ; Draw question
         LDA #$29        ; C3/B616
         STA $26         ; Next: Sell list
         RTS

; Invoke buy order menu if justified
C3B7E6:  JSR C3BFC2      ; Selected item
         JSR itm_cl1     ; Tool class?
         BNE C3B80A      ; Branch if not
         JSR C3BC92      ; Define $64
         LDA $64         ; Owning none?
         BEQ C3B80A      ; Test GP if so
         JSR C30EC0      ; Play buzzer
         LDY #C3C3F5     ; Text pointer
         JSR C302F9      ; Draw excuse
         BRA C3B87D      ; Set to exit

; Fork: Check if enough money
C3B80A:  LDA $1862       ; GP > 65535?
         BNE C3B83E      ; Ample if so
         TDC             ; ...
         LDA $4B         ; Selected slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $7E9F09,X   ; Item's price
         CMP $1860       ; Got as much?
         SEP #$20        ; 8-bit A
         BEQ C3B83E      ; Ample if so
         BCC C3B83E      ; Or if more
         JSR C30EC0      ; Play buzzer
         LDY #C3C3CE     ; Text pointer
         JSR C302F9      ; Draw excuse
         BRA C3B87D      ; Set to exit

; Sub: Define buy quantity limit
C3B82F:  LDA $64         ; Qty in stock
         CLC             ; Prepare ADC
         ADC $65         ; Add qty worn
         STA $69         ; Set total owned
         LDA #$63        ; Quantity: 99
         SEC             ; Prepare SBC
         SBC $69         ; Sub total owned
         STA $6A         ; Set buy limit
         RTS

; Fork: Check if owning 99
C3B83E:  LDA $69         ; Qty owned/worn
         CMP #$63        ; Under 99?
         BCC C3B850      ; Okay if so
         JSR C30EC0      ; Play buzzer
         LDY #C3C3E2     ; Text pointer
         JSR C302F9      ; Draw "Too many!"
         BRA C3B87D      ; Set to exit

; Fork: Can buy item
C3B850:  JSR C30EB2      ; Sound: Click
         LDX #$3408      ; Pos: 8, 52
         STX $55         ; Set cursor's
         LDA #$27        ; C3/B505
         STA $26         ; Next: Order menu
         JSR C3BAA5      ; Draw blue text
         JSR C3BABA      ; Draw item info
         LDY #C3C396     ; Text pointer
         JSR C302F9      ; Draw "How many?"

; Fork: Switch screen
C3B86D:  LDY #$0100      ; Y: 256
         STY $3B         ; Set BG2 Y-Pos
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         JSR C3A796      ; Clear desc GFX
         JMP C3A6F4      ; Build desc map

; Set to return to Buy menu after delay
C3B87D:  LDA #$28        ; C3/B60E
         STA $26         ; Next: Exit
         LDA #$20        ; Frames: 32
         STA $20         ; Set delay
         RTS

; Load navigation data for main shop menu
C3B886:  LDY #C3B895     ; C3/B895
         JMP C305FE      ; Load navig data

; Handle D-Pad for main shop menu
C3B88C:  JSR C3072D      ; Handle D-Pad
C3B88F:  LDY #C3B89A     ; C3/B89A
         JMP C30640      ; Relocate cursor

; Handle D-Pad for Buy menu
C3B8A6:  JSR C3072D      ; Handle D-Pad
C3B8A9:  LDY #C3B8B4     ; C3/B8B4
         JMP C30640      ; Relocate cursor

; Draw main shop menu and submenu windows, set to update description
C3B8C4:  JSR bg2c_cl     ; Clear BG2 maps
         LDX #C3BC1B     ; C3/BC1B
         JSR boxes_      ; Draw windows
         JSR C30E60      ; Upload BG2 C+D
         JSR C3B94E      ; Clear BG1 maps
         JSR C3B95A      ; Draw title, GP
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         LDY #C3C36F     ; Text pointer
         JSR C302F9      ; Draw greeting
         JSR C31B99      ; Queue desc anim
         JMP up_txt      ; Upload text maps

; Clear BG1 tilemaps
C3B94E:  JSR C36A23      ; Clear BG1 map D
bg1c_cl: JSR C36A1E      ; Clear BG1 map C
bg1b_cl: JSR C36A19      ; Clear BG1 map B
         JMP C36A15      ; Clear BG1 map A

; Draw shop title and party's gold, clear rest of BG3
C3B95A:  JSR bg3c_cl     ; Clear BG3 A-C
         JSR C3BFD3      ; Draw title
;        JSR C3C2F7      ; Color: Blue
         LDY #C3C338     ; Text pointer
         JSR C302F9      ; Draw "GP"
         JSR C3C2F2      ; Color: User's
         PEA $7A33       ; Text position
         JMP gp_pty      ; Draw GP total

; Draw all text for Buy menu
C3B986:  JSR C3B95A      ; Draw title, GP
         LDY #C3C385     ; Text pointer
         JSR C302F9      ; Draw "Help..."
         JSR C3C2E1      ; Draw Owned, Eqpd
         LDY $00         ; Clear Y
         STY $F1         ; Menu slot: 1
         STZ $E6         ; List size: 0
C3B998:  REP #$20        ; 16-bit A
         LDA $F1         ; Menu slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3B9FC,X  ; Tilemap ptr
         STA $7E9E89     ; Set position
         LDA $F1         ; Menu slot
;        CLC             ; Prepare ADC
         ADC $67         ; Add shop index
         INC A           ; Skip flags
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $C47AC0,X   ; Shop item
         LDX $F1         ; Menu slot
         STA $7E9D89,X   ; Assign item
         CMP #$FF        ; Nothing?
         BEQ C3B9E4      ; Branch if so
         PHA             ; Memorize item
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name
         PLA             ; Item in slot
         JSR C38321      ; Compute index
         JSR C3BA0C      ; Define price
         JSR C3052E      ; Turn into text
         REP #$21        ; 16-bit A; C-
         LDA $7E9E89     ; Tilemap ptr
         ADC #$001A      ; Skip item name
         TAX             ; Put sum in X
         JSR C3049A      ; Draw price
         INC $E6         ; List size +1
C3B9E4:  LDY $F1         ; Menu slot
         INY             ; Menu slot +1
         STY $F1         ; Save changes
         CPY #$0008      ; Done 8 items?
         BNE C3B998      ; Loop if not
         LDA $E6         ; List size
         STA $54         ; Set cursor limit
         JSR C3BC57      ; Get qties owned
         JSR C3BC84      ; Draw qty owned
         JMP C3BCA8      ; Draw qty worn

; Define cost to buy item
C3BA0C:  REP #$20        ; 16-bit A
         LDA $D8501C,X   ; Base price
         JSR C3BA2C      ; Apply multiplier
         STA $F3         ; Memorize result
         LDA $F1         ; Menu slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $F3         ; Modified price
         STA $7E9F09,X   ; Set item price
         SEP #$20        ; 8-bit A
         RTS

; Apply price multiplier for Buy menu
C3BA2C:  PHA             ; Save price
         LDX $67         ; Shop index
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $C47AC0,X   ; Shop flags
         AND #$38        ; Get modifier
         REP #$20        ; 16-bit A
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         TAX             ; Index it
         PLA             ; Base price
         JMP (C3BA41,X)  ; Apply modifier

; Jump table for price multipliers
C3BA41:  dw C3BA55       ; 100%
         dw C3BA4F       ; 150%
         dw C3BA56       ; 200%
         dw C3BA58       ; 50%
         dw C3BA5A       ; 50% if female leads, 150% otherwise
         dw C3BA76       ; 50% if male leads, 150% otherwise
         dw C3BA92       ; 50% if Edgar leads

; Double price (unused)
C3BA56:  ASL A           ; Double price
         RTS

; Halve price if female leads, raise by 50% otherwise (unused)
C3BA5A:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         BEQ C3BA71      ; -50% if Terra
         CMP #$06        ; Celes?
         BEQ C3BA71      ; Halve if so
         CMP #$08        ; Relm?
         REP #$20        ; 16-bit A
         BEQ C3BA71      ; Halve if so
         PLA             ; Base price
         BRA C3BA4F      ; Add 50%
C3BA71:  PLA             ; Base price

; Halve price
C3BA58:  LSR A           ; Halve price
         RTS

; Halve price if male leads, raise by 50% otherwise (unused)
C3BA76:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         BEQ C3BA8D      ; +50% if Terra
         CMP #$06        ; Celes?
         BEQ C3BA8D      ; +50% if so
         CMP #$08        ; Relm?
         REP #$20        ; 16-bit A
         BEQ C3BA8D      ; +50% if so
         PLA             ; Base price
         BRA C3BA58      ; Halve it
C3BA8D:  PLA             ; Base price

; Increase price by 50% (unused)
C3BA4F:  STA $E7         ; Save price
         LSR A           ; Halve it
         CLC             ; Prepare ADC
         ADC $E7         ; Add base price
C3BA55:  RTS

; Halve price if Edgar leads
C3BA92:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         CMP #$04        ; Edgar?
         REP #$20        ; 16-bit A
         BEQ C3BAA0      ; Halve if so
         PLA             ; Base price
         RTS             ; Exit
C3BAA0:  PLA             ; Base price
         BRA C3BA58      ; Halve it

; Draw blue text for shop order menu, position item name
C3BAA5:  JSR C30F39      ; Queue BG3 upload
         JSR C3B95A      ; Clean up BG3
         JSR C3C2E1      ; Draw Owned, Eqpd
         LDY #$7A0F      ; Tilemap ptr
         JMP C33519      ; Set item position

; Draw item specs for buy order menu, reset buy quantity
C3BABA:  JSR C3BAEC      ; Draw power info
         JSR C3BC84      ; Draw qty owned
         JSR C3BCA8      ; Draw qty worn
         JSR C3BFC2      ; Selected item
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name
         LDA #$01        ; Quantity: 1
         STA $28         ; Set order size
         JMP C3BBAE      ; Draw size, value

; Draw item specs for sell order menu, reset sell quantity
C3BAD3:  JSR C3BC9D      ; Draw qty owned
         JSR C3BF66      ; Draw qty worn
         JSR C3BAF2      ; Draw power info
         JSR C3BFCB      ; Selected item
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name
         LDA #$01        ; Quantity: 1
         STA $28         ; Set order size
         JMP C3BBB7      ; Draw size, value

; Draw power-related text for Buy menu
C3BAEC:  JSR C3BFC2      ; Selected item
         BRA C3BAF8      ; Draw power info

; Draw power-related text for Sell menu
C3BAF2:  JSR C3BFCB      ; Selected item

; Draw power-related text for Buy or Sell menu
C3BAF8:  JSR itm_cl1     ; Tool class?
         BEQ C3BBAD      ; Exit if so
         CMP #$06        ; Consumable?
         BEQ C3BBAD      ; Exit if so
         DEC A           ; Weapon?
         BEQ C3BB30      ; Branch if so
         JSR C3C2F2      ; Color: User's
         LDA $D85014,X   ; Defense
         JSR C304E0      ; Turn into text
         LDX #$7BA9      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C3C2F7      ; Color: Blue
         LDY #C3C361     ; Text pointer
         JSR C302F9      ; Draw "Defense"
         BRA C3BB3_      ; Draw "…"

; Fork: Handle weapon
C3BB30:  JSR C3C2F2      ; Color: User's
         LDA $D85014,X   ; Bat.Pwr
         JSR C304E0      ; Turn into text
         LDX #$7BA9      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C3C2F7      ; Color: Blue
         LDY #C3C357     ; Text pointer
         JSR C302F9      ; Draw "Bat Pwr"
C3BB3_:  LDY #C3C36B     ; Text pointer
         JSR C302F9      ; Draw "…"
         JMP C3C2F2      ; Color: User's
                         ; For Owned, etc.

; Compute buy order value
C3BB53:  TDC             ; Clear A
         LDA $4B         ; Item slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $7E9F09,X   ; Price asked
         BRA C3BB81      ; Price x size

; Compute sell order value
C3BB65:  JSR C3BFCB      ; Selected item
         JSR C38321      ; Compute index
         REP #$21        ; 16-bit A; C-
         LDA $D8501C,X   ; Base price
         LSR A           ; Halve it

; Compute buy or sell order value
C3BB81:  SEP #$20        ; 8-bit A
         PHY             ; Save Y
         TAY             ; Item value
         LDA $28         ; Item quantity
         JSR mul16       ; Value x size
         STX $F1         ; Set total LBs
         STA $F3         ; Set total HB
         PLY             ; Restore Y
C3BBAD:  RTS

; Draw buy order size and value
C3BBAE:  JSR C3BBC0      ; Draw order size
         JSR C3BB53      ; Get order value
         BRA C3BBD7      ; Draw order value

; Draw sell order size and value
C3BBB7:  JSR C3BBC0      ; Draw order size
         JSR C3BB65      ; Get order value
C3BBD7:  JSR C30582      ; Turn into text
         LDX #$7AA1      ; Text position
         JMP C304AC      ; Draw 7 digits

; Draw traded item's quantity and "GP" below
C3BBC0:  JSR C3C2F7      ; Color: Blue
         LDY #C3C33D     ; Text pointer
         JSR C302F9      ; Draw "GP"
         JSR C3C2F2      ; Color: User's
         LDA $28         ; Order size
         JSR C304E0      ; Turn into text
         LDX #$7A2B      ; Text position
         JMP C304B6      ; Draw 2 digits

; Initialize cursor data and draw inventory for Sell menu
C3BBE0:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$F5        ; Top row: Slot 246
         STA $5C         ; Set scroll limit
         LDX #$010A      ; Onscreen rows: 10
         STX $5A         ; Onscreen cols: 1
         JSR C37D1C      ; Load navig data
         LDY $4D         ; Cursor position
         STY $4F         ; Set as list loc
         LDA $4A         ; Scroll position
         CLC             ; Prepare ADC
         ADC $50         ; Add list V-Slot
         STA $50         ; Set list V-Slot
         JSR C37D25      ; Relocate cursor
C3BC02:  JSR C37E0D      ; Draw inventory
C3BC0_:  LDA #$58        ; Y: 88
         LDY #$0070      ; V-Speed: 0.44 px
         JMP C3091F      ; Create scrollbar

; Compile quantity owned of each item in Buy menu
C3BC57:  LDX #$9DC9      ; 7E/9DC9
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         TAX             ; Menu slot: 1
C3BC5F:  LDY $00         ; Stock slot: 1
         LDA $7E9D89,X   ; Shop item
C3BC66:  CMP $1869,Y     ; In stock slot?
         BEQ C3BC76      ; Branch if so
         INY             ; Stock slot +1
         CPY #$0100      ; Done all 256?
         BNE C3BC66      ; Loop if not
         TDC             ; Quantity: 0
         BRA C3BC79      ; Skip a line
C3BC76:  LDA $1969,Y     ; Quantity owned
C3BC79:  STA $2180       ; Set shop item's
         INX             ; Menu slot +1
         CPX #$0008      ; Done 8 items?
         BNE C3BC5F      ; Loop if not
         RTS

; Load and draw quantity owned of item in Buy menu
C3BC84:  JSR C3BC92      ; Define $64
C3BC87:  LDA $64         ; Quantity owned
         JSR C304E0      ; Turn into text
         LDX #$7B3F      ; Text position
         JMP C304B6      ; Draw 2 digits

; Get quantity owned of item in Buy menu
C3BC92:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9DC9,X   ; Quantity owned
         STA $64         ; Set as current
         RTS

; Load and draw quantity owned of item in Sell menu
C3BC9D:  TDC             ; Clear A
         LDA $4B         ; List slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         STA $64         ; Memorize it
         BRA C3BC87      ; Draw quantity

; Count and draw quantity worn of item in Buy menu
C3BCA8:  JSR C3BFC2      ; Item in slot
         JMP C3BF69      ; Draw quantity

; Get sign found by actor for shop item
C3BCAE:  STA $E0         ; Save actor slot
         JSR C3BCC9      ; Actor can use?
         BCC C3BCC7      ; No sign if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         JSR x16         ; x16
         ADC $E0         ; Add char slot
         TAX             ; Index sum
         LDA $AA8D,X     ; Sign
         RTS             ; Exit
C3BCC7:  TDC             ; Sign: None
         RTS

; Check whether actor can equip shop item
C3BCC9:  STZ $11D8       ; No Merit Award
         TAX             ; Index actor
         LDA $9E09,X     ; Actor in slot
         JSR C39C48      ; Define compat
         JSR C3BFC2      ; Item
         JSR C38321      ; Compute index
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         AND $E7         ; Actor can use?
         SEP #$20        ; 8-bit A
         BEQ C3BCFA      ; Branch if not
         SEC             ; Mark success
         RTS             ; Exit
C3BCFA:  CLC             ; Mark failure
         RTS

; Build sign list for each item in Buy menu
C3BCFD:  LDX #$AA8D      ; 7E/AA8D
         STX $F3         ; Save WRAM adr
         LDY #$0080      ; 8 items x 16
         JSR clr_ram     ; Clear sign list
         LDX $00         ; Item slot: 1
C3BD07:  LDY $F3         ; WRAM address
         STY $2181       ; Set WRAM LBs
         PHX             ; Save item slot
         LDA $7E9D89,X   ; Item in slot
         STA $9F         ; Memorize it
         JSR C38321      ; Compute index
         LDA $D85014,X   ; Item's power
         STA $9E         ; Memorize it
         JSR itm_cl2     ; Item class
         ASL A           ; Double it
         TAX             ; Index it
         JSR (signtbl,X) ; Build list
         REP #$21        ; 16-bit A; C-
         LDA $F3         ; WRAM address
         ADC #$0010      ; Reach next item
         STA $F3         ; Save changes
         SEP #$20        ; 8-bit A
         PLX             ; Item slot
         INX             ; Item slot +1
         CPX #$0008      ; Done 8 items?
         BNE C3BD07      ; Loop if not
         RTS

; Jump table for the above
signtbl: dw C3BF0A       ; Tool
         dw C3BDA5       ; Weapon
         dw C3BD45       ; Armor
         dw C3BE35       ; Shield
         dw C3BEBD       ; Helmet
         dw C3BF18       ; Relic
         dw C3BF0A       ; Consumable

; Build sign list for weapon
C3BDA5:  LDX $00         ; 1st: Terra
C3BDA7:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BE27      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index in X
         TAY             ; Index in Y
         SEP #$20        ; 8-bit A

; Fork: Check if holding shop item
C3BDBA:  LDA $9F         ; Shop item
         CMP $1F,X       ; In R-Hand?
         BEQ C3BE1E      ; Use "E" if so
         CMP $20,X       ; In L-Hand?
         BEQ C3BE1E      ; Use "E" if so

; Fork: Check if weapon in R-Hand
C3BDC8:  LDA $1F,X       ; R-Hand item
         CMP #$FF        ; None?
         BEQ C3BDE0      ; Branch if so
         JSR itm_cl1     ; Item class
         DEC A           ; Weapon?
         BEQ C3BDFE      ; Branch if so

; Fork: No weapon in R-Hand, check L-Hand
C3BDE0:  LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BEQ C3BE16      ; Use "^" if so
         JSR itm_cl1     ; Item class
         DEC A           ; Weapon?
         BNE C3BDFE      ; Branch if not
         LDA $0020,Y     ; L-Hand item
         BRA C3BE02      ; Compare power

; Fork: Compare weapons' power
C3BDFE:  LDA $001F,Y     ; R-Hand item
C3BE02:  CMP #$FF        ; None?
         BEQ C3BE16      ; Use "^" if so
         JSR C38321      ; Compute index
         LDA $D85014,X   ; Item's Bat.Pwr
         CMP $9E         ; Matches shop's?
         BEQ C3BE22      ; Use "=" if so
         BCS C3BE1A      ; Use "v" if above
C3BE16:  LDA #$02        ; Sign: "^"
         BRA C3BE24      ; Add to list

; Fork: Use "v" sign for weapon
C3BE1A:  LDA #$03        ; Sign: "v"
         BRA C3BE24      ; Add to list

; Fork: Use "E" sign for weapon
C3BE1E:  LDA #$01        ; Sign: "E"
         BRA C3BE24      ; Skip a line

; Fork: Use "=" sign for weapon
C3BE22:  LDA #$04        ; Sign: "="
C3BE24:  STA $2180       ; Add to list
C3BE27:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BDA7      ; Loop if not
         RTS

; Build sign list for shield
C3BE35:  LDX $00         ; 1st: Terra
C3BE37:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BEAF      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A

; Fork: Check if holding shop item
C3BE4A:  LDA $9F         ; Shop item
         CMP $001F,Y     ; In R-Hand?
         BEQ C3BEA6      ; Use "E" if so
         CMP $0020,Y     ; In L-Hand?
         BEQ C3BEA6      ; Use "E" if so

; Fork: Check if holding a shield
C3BE58:  LDA $0020,Y     ; L-Hand item
         JSR itm_cl1     ; Item class
         CMP #$03        ; Shield?
         BEQ C3BE86      ; Branch if so
         LDA $001F,Y     ; R-Hand item
         JSR itm_cl1     ; Item class
         CMP #$03        ; Shield?
         BNE C3BE9E      ; Use "^" if not
         LDA $001F,Y     ; R-Hand item
         BRA C3BE8A      ; Compare defense

; Fork: Compare shields' defense
C3BE86:  LDA $0020,Y     ; L-Hand item
C3BE8A:  CMP #$FF        ; None?
         BEQ C3BE9E      ; Use "^" if so
         JSR C38321      ; Compute index
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3BEAA      ; Use "=" if so
         BCS C3BEA2      ; Use "v" if above
C3BE9E:  LDA #$02        ; Sign: "^"
         BRA C3BEAC      ; Add to list

; Fork: Use "v" sign for shield
C3BEA2:  LDA #$03        ; Sign: "v"
         BRA C3BEAC      ; Add to list

; Fork: Use "E" sign for shield
C3BEA6:  LDA #$01        ; Sign: "E"
         BRA C3BEAC      ; Skip a line

; Fork: Use "=" sign for shield
C3BEAA:  LDA #$04        ; Sign: "="
C3BEAC:  STA $2180       ; Add to list
C3BEAF:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BE37      ; Loop if not
         RTS

; Build sign list for armor
C3BD45:  LDA #$01        ; Point to armor
         BRA C3BEB_      ; Skip a line

; Build sign list for helmet
C3BEBD:  TDC             ; Point to helmet
C3BEB_:  STA $FF         ; Set address mod
         LDX $00         ; 1st: Terra
C3BEBF:  PHX             ; Save char index
         REP #$21        ; 16-bit A; C-
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BEFF      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         ADC $FF         ; +1 if armor slot
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $21,X       ; Armor or helmet
         CMP $9F         ; In shop slot?
         BEQ C3BEF6      ; Use "E" if so
         CMP #$FF        ; None?
         BEQ C3BEEE      ; Use "^" if so
         JSR C38321      ; Compute index
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3BEFA      ; Use "=" if so
         BCS C3BEF2      ; Use "v" if above
C3BEEE:  LDA #$02        ; Sign: "^"
         BRA C3BEFC      ; Add to list

; Fork: Use "v" sign for armor or helmet
C3BEF2:  LDA #$03        ; Sign: "v"
         BRA C3BEFC      ; Add to list

; Fork: Use "E" sign for armor or helmet
C3BEF6:  LDA #$01        ; Sign: "E"
         BRA C3BEFC      ; Skip a line

; Fork: Use "=" sign for armor or helmet
C3BEFA:  LDA #$04        ; Sign: "="
C3BEFC:  STA $2180       ; Add to list
C3BEFF:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BEBF      ; Loop if not
         RTS

; Clear sign list for consumable or tool
C3BF0A:  LDA #$10        ; Actors: 16
C3BF0C:  STZ $2180       ; Clear a sign
         DEC A           ; One less left
         BNE C3BF0C      ; Loop till last
         RTS

; Build sign list for relic
C3BF18:  LDX $00         ; 1st: Terra
C3BF1A:  PHX             ; Save char index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BF44      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $9F         ; Shop item
         CMP $23,X       ; In relic slot 1?
         BEQ C3BF3F      ; Use "E" if so
         CMP $24,X       ; In relic slot 2?
         BEQ C3BF3F      ; Use "E" if so
         TDC             ; Sign: None
         BRA C3BF41      ; Skip a line
C3BF3F:  LDA #$01        ; Sign: "E"
C3BF41:  STA $2180       ; Add to list
C3BF44:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BF1A      ; Loop if not
         RTS

; Count and draw quantity worn of item in Sell menu
C3BF66:  JSR C3BFCB      ; Selected item
C3BF69:  STA $E0         ; Memorize it
         STZ $65         ; Quantity worn: 0
         LDX #$161F      ; 00/161F
         STX $E7         ; Set address LBs
         STZ $E9         ; Address HB: 000
         LDX $00         ; 1st: Terra
C3BF78:  PHX             ; Save actor slot
         REP #$20        ; 16-bit A
         TXA             ; Get actor
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Eligible actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BFA5      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $00,X       ; Actor
         CMP #$0E        ; Guest?
         BCS C3BFA5      ; Skip if so
         LDY $00         ; 1st: R-Hand
C3BF97:  LDA [$E7],Y     ; Equipped item
         CMP $E0         ; Matches shop's?
         BNE C3BF9F      ; Branch if not
         INC $65         ; Quantity worn +1
C3BF9F:  INY             ; Gear slot +1
         CPY #$0006      ; Done all 6?
         BNE C3BF97      ; Loop if not
C3BFA5:  REP #$21        ; 16-bit A; C-
         LDA #$0025      ; Actor data size
         ADC $E7         ; Add SRAM pointer
         STA $E7         ; Set SRAM pointer
         SEP #$20        ; 8-bit A
         PLX             ; Actor slot
         INX             ; Point to next
         CPX #$0010      ; Done all 16?
         BNE C3BF78      ; Loop if not
         LDA $65         ; Quantity worn
         JSR C304E0      ; Turn into text
         LDX #$7C3F      ; Text position
         JMP C304B6      ; Draw 2 digits

; Get list entry by cursor
C3BFC2:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Item in slot
         RTS

; Get inventory item by cursor
C3BFCB:  TDC             ; Clear A
         LDA $4B         ; List slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         RTS

; Draw shop title and define shop index
C3BFD3:  JSR C3C2F7      ; Color: Blue
C3BFD6:  LDA $0201       ; Shop number
         XBA             ; Put in B
         LDA #$09        ; Shop data size
         JSR mul8        ; Number x size
         TAX             ; Index product
         STX $67         ; Set shop index
         TDC             ; Clear A
         LDA $C47AC0,X   ; Shop flags
         AND #$07        ; Title number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3C00C-2,X; Text pointer
         TAY             ; Set src LBs
         JMP C302F9      ; Draw title

; Pointers to shop titles
C3C00C:  dw C3C2FC       ; Weapon
         dw C3C305       ; Armor
         dw C3C30D       ; Item
         dw C3C314       ; Relics
         dw C3C31D       ; Vendor

; Load item's name
C3C068:  JSR C3C06_      ; Load name
         STZ $2180       ; End string
         RTS

; Load item's name without ending string
C3C06_:  XBA             ; Put item in B
         LDX.W #!itm_ns  ; Letters: 13
         LDA.B #!itm_np!h; Text ptr HB
         LDY.W #!itm_np  ; Text ptr LBs
         JMP fw_txt      ; Load name

; Compile and create actors for Buy menu
C3C09A:  JSR C3C109      ; Compile actors
         JSR C3C1CC      ; Mark members
         TDC             ; Clear A
         TAX             ; List slot: 1
C3C0A2:  LDA $7E9E09,X   ; Actor in slot
         BMI C3C140      ; Exit if none
         PHX             ; Save slot
         PHA             ; Save actor
         LDY #C3C141     ; C3/C141
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue slot
         TDC             ; Clear A
         PLA             ; Actor
         STA $7E35C9,X   ; Link to OBJ
         JSR C378FA      ; Set anim ptr
         PLX             ; List slot
         LDA.L C3C0ED,X  ; X position
         STA $33CA,Y     ; Set actor's
         LDA.L C3C0FB,X  ; Y position
         STA $344A,Y     ; Set actor's
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         INX             ; List slot +1
         BRA C3C0A2      ; Do next char

; Compile actors for Buy menu
C3C109:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         LDX $00         ; 1st: Terra
C3C111:  PHX             ; Save char slot
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Showable chars
         AND.L C39C67,X  ; Has our actor?
         BEQ C3C132      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor
         CMP #$0E        ; Guest?
         BCS C3C132      ; Skip if so
         STA $2180       ; Add to list
C3C132:  SEP #$20        ; 8-bit A
         PLX             ; Actor slot
         INX             ; Slot +1
         CPX #$0010      ; Done all 16?
         BNE C3C111      ; Loop if not
         LDA #$FF        ; Terminator
         STA $2180       ; End list
C3C140:  RTS

; Update shop actor
C3C141:  BNE C3C16A      ; If mode 1

; Mode 0: Initialize data
C3C149:  LDA #$01        ; Hide actors: N
         TSB $47         ; Set menu flag
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim table ptr
         STA $34CA,X     ; Save original
         JSR C31206      ; Set pose timer
;        LDA $47         ; Menu flags
;        AND #$08        ; Shop mode?...
;        BNE C3C16A      ; Branch if not
         JSR C3C1F0      ; Create big arrow

; Mode 1: Sustain sprite
C3C16A:  LDA $47         ; Menu flags
         LSR A           ; Remove actors?
         BCC C3C19A      ; Delete if so
         LDX $2D         ; Queue index
         LDA $47         ; Menu flags
         AND #$08        ; Shop mode?...
         BNE C3C189      ; Branch if not
         LDA $35C9,X     ; Actor
         JSR C3BCC9      ; Waving arms?
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         BCC C3C189      ; If not waving
         LDA $34CA,X     ; Base anim ptr
         CLC             ; Prepare ADC
         ADC #$0009      ; Adjust value
         BRA C3C190      ; Set real ptr
C3C189:  LDA $34CA,X     ; Base anim ptr
C3C190:  STA $32C9,X     ; Set as current
         JMP oamsec      ; Set OAM; requeue
C3C19A:  CLC             ; Set to dequeue
         RTS

; Compile party members for Buy menu
C3C1CC:  LDX #$9E01      ; 7E/9E01
         STX $2181       ; Set WRAM LBs
         LDY $00         ; Member index: 0
C3C1D4:  LDX $6D,Y       ; Actor's address
         BEQ C3C1E3      ; Skip if nobody
         LDA $00,X       ; Actor in slot
         BRA C3C1E5      ; Skip a line
C3C1E3:  LDA #$FF        ; Actor: None
C3C1E5:  STA $2180       ; Add to list
         INY             ; Member index +1
         INY             ; Member index +1
         CPY #$0008      ; Done 4 members?
         BNE C3C1D4      ; Loop if not
         RTS

; Create arrow under shop actor if in party
C3C1F0:  LDY #$0003      ; Member slot: 4
C3C1F4:  LDA $35C9,X     ; Shop actor
         CMP $9E01,Y     ; In member slot?
         BNE C3C234      ; Try next if not
         PHX             ; Save queue index
         PHY             ; Save member slot
         LDY #C37B42     ; C3/7B42
         JSR qanim0      ; Queue OAM fn
         JSR db7e        ; Set DB to 7E
         LDA #$D8        ; Anim ptr HB
         LDY #$EBA9      ; Anim ptr LBs
         JSR anm_st      ; Set arrow's
         LDY $374A,X     ; Actor's index
         LDA $33CA,Y     ; Actor's X
         STA $33CA,X     ; Set arrow's
         LDA $344A,Y     ; Actor's Y
         DEC A           ; +1 px up
         DEC A           ; +1 px up
         STA $344A,X     ; Set arrow's Y
         PLY             ; Member slot
         PLX             ; Queue index
C3C234:  DEY             ; Member slot -1
         BPL C3C1F4      ; Loop till last
         RTS

; Create sign by each actor in Buy menu
C3C23B:  TDC             ; Clear A
         TAY             ; Char slot: 1
C3C23D:  PHY             ; Save char slot
         LDA #$04        ; Min slot: 32
         LDY #C3C253     ; C3/C253
         JSR C31173      ; Queue OAM fn
         PLY             ; Char slot
         TYA             ; Put in A
         STA $7E35C9,X   ; Assign to sign
         INY             ; Char slot +1
         CPY #$000E      ; Done all 14?
         BNE C3C23D      ; Loop if not
         RTS

; Update shop sign
C3C253:  BNE C3C28B      ; If mode 1

; Mode 0: Initialize sprite
C3C25B:  LDA #$D8        ; Anim ptr HB
         LDY #$EBCD      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         REP #$20        ; 16-bit A
;        TYA             ; Anim table ptr
         STA $34CA,X     ; Set original
         SEP #$20        ; 8-bit A
         INC $3649,X     ; Mode +1
         TDC             ; Clear A
         LDA $35C9,X     ; Char slot
         TXY             ; Queue index
         TAX             ; Index slot
         LDA $D8EBB1,X   ; X position
         STA $33CA,Y     ; Set sign's
         LDA $D8EBBF,X   ; Y position
         STA $344A,Y     ; Set sign's
         JSR C3120_      ; Set pose timer

; Mode 1: Sustain sprite
C3C28B:  LDA $47         ; Menu flags
         LSR A           ; Actors shown?
         BCC C3C2DF      ; Delete if not
         TDC             ; ...
         LDA $35C9,X     ; Char slot
         JSR C3BCAE      ; Sign
         BEQ C3C2DD      ; Exit if none
         REP #$21        ; 16-bit A; C-
         LDX $2D         ; Queue index
         DEC A           ; Equipped?
         BEQ C3C2B6      ; Branch if so
         DEC A           ; Up?
         BEQ C3C2CB      ; Branch if so
         DEC A           ; Down?
         BEQ C3C2AA      ; Branch if so

; Fork: Equal sign
C3C2BF:  LDA $34CA,X     ; Base anim ptr
         ADC #$0024      ; Adjust value
         BRA C3C2D5      ; Set real ptr

; Fork: Equipped sign
C3C2B6:  LDA $34CA,X     ; Base anim ptr
         BRA C3C2D5      ; Set as current

; Fork: Down sign
C3C2AA:  LDA $34CA,X     ; Base anim ptr
         ADC #$0018      ; Adjust value
         BRA C3C2D5      ; Set real ptr

; Fork: Up sign
C3C2CB:  LDA $34CA,X     ; Base anim ptr
         ADC #$000C      ; Adjust value
C3C2D5:  STA $32C9,X     ; Set real ptr
         JSR C31221      ; Define OAM
C3C2DD:  SEC             ; Set to requeue
         RTS

; Fork: Delete sign
C3C2DF:  CLC             ; Set to dequeue
         RTS

; Draw "Owned:" and "Equipped:" for Buy menu
C3C2E1:  JSR C3C2F7      ; Color: Blue
         LDY #C3C342     ; Text pointer
         JSR C302F9      ; Draw "Owned:"
         LDY #C3C34B     ; Text pointer
         JSR C302F9      ; Draw "Equipped:"

; Set text color to player's color
C3C2F2:  LDA #$20        ; Palette 0
         BRA st_29       ; Color: User's

; Set text color to blue
C3C2F7:  LDA #$2C        ; Palette 3
         BRA st_29       ; Color: Blue

; Set text color to gray (BG1) or blue (BG3)
txt30:   LDA #$30        ; Palette 4
st_29:   STA $29         ; Color: Gray
         RTS

; =============================================================================

; Jump table for ending sequences
C3C406:  dw C3C5BE       ; 00: Fade screen before ending scene
         dw C3C5D4       ; 01: Return to event script
         dw C3C869       ; 02: Show aerial-view panning clouds
         dw C3C8A6       ; 03: Wait before fading screen
         dw C3C8AD       ; 04: Show spinning clouds
         dw C3C5E1       ; 05: Start sideview airship scene
         dw C30000       ; 06: Unused...
         dw C30000       ; 07: Unused...
         dw C30000       ; 08: Unused...
         dw C3C794       ; 09: Start aerial-view airship scene
         dw C3C7D2       ; 0A: Show aerial-view airship
         dw C3C7E1       ; 0B: Fade screen to white
         dw C3C8D1       ; 0C: Start boat scene
         dw C3C917       ; 0D: Show boat sprite
         dw C30000       ; 0E: Unused...
         dw C30000       ; 0F: Unused...
         dw C3C9CD       ; 10: Start skimming airship scene
         dw C3CA8C       ; 11: Show swooping bird
         dw C30000       ; 12: Unused...
         dw C30000       ; 13: Unused...
         dw C3CD17       ; 14: Start frontview airship scene
         dw C3CDA0       ; 15: Show late bird flock
         dw C30000       ; 16: Unused...
         dw C30000       ; 17: Unused...
         dw C3CEA6       ; 18: Start aerial-view plains scene
         dw C30000       ; 19: Unused...
         dw C30000       ; 1A: Unused...
         dw C30000       ; 1B: Unused...
         dw C3CEEC       ; 1C: Start rearview airship scene
         dw C30000       ; 1D: Unused...
         dw C30000       ; 1E: Unused...
         dw C30000       ; 1F: Unused...
         dw C3D02F       ; 20: Start final airship scene
         dw C3D096       ; 21: Fade final airship
         dw C30000       ; 22: Unused...
         dw C30000       ; 23: Unused...
         dw C30000       ; 24: Unused...
         dw C30000       ; 25: Unused...
         dw C30000       ; 26: Unused...
         dw C30000       ; 27: Unused...
         dw C3E26E       ; 28: Start Shadow's scene
         dw C3E2B2       ; 29: Fade in "Shadow as"
         dw C3E2C1       ; 2A: Switch Shadow's names
         dw C3E2D0       ; 2B: Fade all but Shadow's name
         dw C30000       ; 2C: Unused...
         dw C3E6CE       ; 2D: Start first book scene
         dw C3E6DF       ; 2E: Animate first book
         dw C3E6EE       ; 2F: Wait 480 frames
         dw C3E6FA       ; 30: Pixelate and fade first book
         dw C30000       ; 31: Unused...
         dw C3E2F8       ; 32: Start Cyan's scene
         dw C3E319       ; 33: Fade in "Cyan as"
         dw C3E328       ; 34: Switch Cyan's names
         dw C3E337       ; 35: Fade all but Cyan's name
         dw C30000       ; 36: Unused...
         dw C30000       ; 37: Unused...
         dw C3E2E7       ; 38: Fade actor's true name
         dw C30000       ; 39: Unused...
         dw C30000       ; 3A: Unused...
         dw C30000       ; 3B: Unused...
         dw C3E3E1       ; 3C: Start Mog's scene
         dw C3E3FD       ; 3D: Fade in "Mog as"
         dw C3E40C       ; 3E: Switch Mog's names
         dw C3E41B       ; 3F: Fade all but Mog's name
         dw C3E34B       ; 40: Start Edgar and Sabin's scene
         dw C3E364       ; 41: Fade in "Edgar as"
         dw C3E373       ; 42: Switch Edgar's names
         dw C3E382       ; 43: Show Sabin's name, fade Edgar's
         dw C3E3A2       ; 44: Delete Edgar's name
         dw C3E3B2       ; 45: Switch Sabin's names
         dw C3E432       ; 46: Start Gogo's scene
         dw C3E459       ; 47: Fade in "Gogo as"
         dw C3E47C       ; 48: Switch Gogo's names
         dw C3E48B       ; 49: Fade all but Gogo's name
         dw C3E711       ; 4A: Start last book scene
         dw C3E72A       ; 4B: Wait 180 frames
         dw C3E736       ; 4C: Stop last book and fade in text
         dw C3E749       ; 4D: Pixelate and fade last book
         dw C30000       ; 4E: Unused...
         dw C3E3CD       ; 4F: Fade all but Sabin's name
         dw C3E4FA       ; 50: Start Gau's scene
         dw C3E513       ; 51: Fade in "Gau as"
         dw C3E522       ; 52: Switch Gau's names; create face
         dw C3E534       ; 53: Fade all but Gau's name
         dw C30000       ; 54: Unused...
         dw C30000       ; 55: Unused...
         dw C30000       ; 56: Unused...
         dw C30000       ; 57: Unused...
         dw C30000       ; 58: Unused...
         dw C30000       ; 59: Unused...
         dw C3E54B       ; 5A: Start Terra's scene
         dw C3E564       ; 5B: Fade in "Terra as"
         dw C3E573       ; 5C: Switch Terra's names, create glint
         dw C3E585       ; 5D: Fade all but Terra's name
         dw C30000       ; 5E: Unused...
         dw C30000       ; 5F: Unused...
         dw C30000       ; 60: Unused...
         dw C30000       ; 61: Unused...
         dw C30000       ; 62: Unused...
         dw C30000       ; 63: Unused...
         dw C3E59C       ; 64: Start Locke and Celes's scene
         dw C3E5B7       ; 65: Fade in "Locke as"
         dw C3E5C6       ; 66: Switch Locke's names
         dw C3E5D5       ; 67: Show Celes's name, fade Locke's
         dw C3E5F5       ; 68: Delete Locke's name
         dw C3E605       ; 69: Switch Celes's names
         dw C3E61E       ; 6A: Fade all but Celes's name
         dw C30000       ; 6B: Unused...
         dw C30000       ; 6C: Unused...
         dw C30000       ; 6D: Unused...
         dw C3E635       ; 6E: Start Relm's scene
         dw C3E651       ; 6F: Fade in "Relm as"
         dw C3E660       ; 70: Switch Relm's names
         dw C3E66F       ; 71: Fade all but Relm's name
         dw C30000       ; 72: Unused...
         dw C30000       ; 73: Unused...
         dw C30000       ; 74: Unused...
         dw C30000       ; 75: Unused...
         dw C30000       ; 76: Unused...
         dw C30000       ; 77: Unused...
         dw C3E686       ; 78: Start Strago's scene
         dw C3E69C       ; 79: Fade in "Strago as"
         dw C3E6AB       ; 7A: Switch Strago's names
         dw C3E6BA       ; 7B: Fade all but Strago's name
         dw C30000       ; 7C: Unused...
         dw C30000       ; 7D: Unused...
         dw C30000       ; 7E: Unused...
         dw C30000       ; 7F: Unused...
         dw C30000       ; 80: Unused...
         dw C30000       ; 81: Unused...
         dw C3E75D       ; 82: Start Setzer's scene
         dw C3E794       ; 83: Fade in "Setzer as"
         dw C3E7A3       ; 84: Switch Setzer's names
         dw C3E7B2       ; 85: Fade background
         dw C3E7C1       ; 86: Fade cards and name
         dw C3E7E5       ; 87: Start Umaro's scene
         dw C3E804       ; 88: Fade in "Umaro as"
         dw C3E813       ; 89: Switch Umaro's names
         dw C3E822       ; 8A: Fade all but Umaro's name

; Display requested ending cinematic
C3C51C:  PHP             ; Push PS
         REP #$30        ; 16-bit A, X, Y
         PHY             ; Push Y
         PHB             ; Push DB
         PHD             ; Push DP
         SEP #$20        ; 8-bit A
         PEI ($00)       ; Push #$0000
         PLD             ; Set DP to 0
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         JSR C300C0      ; Reroute NMI/IRQ
         JSR C368FA      ; Reset variables
         LDY #$012C      ; Scroll delay: 300
         STY $85         ; For true char name
         STZ $B4         ; Blue credits: N
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         JSR C3C586      ; Stop VRAM DMA
         JSR C3C576      ; Disable pad, etc.
         JSL $D4CD48     ; Init registers
;        JSL C3A424      ; Init joypad...
         JSR C31114      ; Reset OAM, queue
         JSR C3DD73      ; Clear VRAM
         JSL $D4CF3B     ; Back up data
         LDA $0201       ; Event parameter
         STA $26         ; Set scene mode
         JSR C3C5A5      ; Handle scene
         JSL $D4CF4B     ; Restore backup
         JSR C3C576      ; Disable pad, etc.
         REP #$30        ; 16-bit A, X, Y
         PLD             ; Pull DP
         PLB             ; Pull DB
         PLY             ; Pull Y
         PLP             ; Pull PS
         RTL

; Disable screen, interrupts, joypad, and HDMA
C3C576:  LDA #$8F        ; BRT: 15 and OFF
         STA $2100       ; Disable screen
         STZ $4200       ; Disable INT, pad
         STZ $420C       ; Disable HDMA
         RTS

; Reset variables for automatic uploads during NMI
C3C586:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $1B         ; Halt VRAM B
         STY $1D         ; Clear src-B LBs
         STA $1F         ; Clear src-B HB
         STY $16         ; Clear src-A LBs
         STA $18         ; Clear src-A HB
         INY             ; Bytes: 1
         STY $19         ; Set data size B
         STY $12         ; Set data size A
         LDY #$7FFF      ; $7FFF
         STY $14         ; Set VRAM ptr A
         RTS

; Enable color addition on BG1
C3C59F:  LDA #$01        ; BG1: ADD mode
         STA $2131       ; Set register
         RTS

; Handle ending sequence
C3C5A5:  TDC             ; Clear A
         LDA $26         ; Scene mode
         CMP #$FF        ; Exit to map?
         BEQ C3C5E0      ; Exit if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JSR (C3C406,X)  ; Handle mode
         JSR C311B0      ; Run anim queue
         JSR C31368      ; Refresh screen
         BRA C3C5A5      ; Loop

; 00: Fade screen before ending scene
C3C5BE:  LDY $20         ; Delay expired?
         BNE C3C5E0      ; Exit if not
         INC $26         ; Next: Exit
         LDA #$0F        ; Frames: 15
         STA $20         ; Set exit delay
         LDY #C3D1FD     ; C3/D1FD
         JMP qanim0      ; Queue fade-out

; 01: Return to event script after delay
C3C5D4:  LDY $20         ; Delay expired?
         BNE C3C5E0      ; Exit if not
;        BRA C3E269      ; End scene

; Set to return to event script
C3E269:  LDA #$FF        ; Null value
         STA $26         ; Next: Exit
         RTS

; Set text for credits to be blue
C3C5DC:  LDA #$01        ; Blue text: Y
         STA $B4         ; Set color mode
C3C5E0:  RTS

; 05: Start sideview airship scene
C3C5E1:  JSR C3C5DC      ; Blue text: Y
         JSL $D4CED7     ; Init registers
         JSR C3D40C      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CBFC     ; Queue HDMA 1-7
         LDY #$0010      ; Zoom-out: 16
         STY $8E         ; Set for airship
         REP #$20        ; 16-bit A
         LDA #$FFF1      ; H-Scroll: -15
         STA $7EB68D     ; Set for airship
         LDA #$002E      ; V-Scroll: 46
         STA $7EB68F     ; Set for airship
         LDA #$0071      ; Center X: 113
         STA $7EB695     ; Set for airship
         LDA #$008D      ; Center Y: 141
         STA $7EB697     ; Set for airship
         SEP #$20        ; 8-bit A
         LDY #$005E      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$2F00      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$0100      ; Center X: 256
         STY $B7         ; Set for clouds
         LDY #$0311      ; Center Y: 785
         STY $B9         ; Set for clouds
         LDY #$0080      ; BG1's X: 128
         STY $35         ; Set for clouds
         LDY #$0291      ; BG1's Y: 657
         STY $37         ; Set for clouds
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D96D      ; Build text OAM
         LDY #C3D7B9     ; C3/D7B9
         JSR qanim2      ; Queue credits
         LDY #C3C681     ; C3/C681
         JSR qanim2      ; Queue M7 anim
         LDY #C3D0F2     ; C3/D0F2
         JSR qanim0      ; Queue rotor anim
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load cloud colors
         JSR C3D018      ; Load sky/plane's
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$021C      ; Frames: 540
         STY $20         ; Set fade delay

; Queue field fade-in
C3C66C:  LDY #C3D1CC     ; C3/D1CC
         JMP qanim0      ; Queue fade-in

; Set brightness before fading in colors manually
C3C675:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         JSR C31368      ; Refresh screen
         LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         RTS

; Shrink sideview airship and scroll clouds
C3C681:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         REP #$20        ; 16-bit A
         BCS C3C6A6      ; Branch if odd
         INC $8E         ; Matrix A +1
C3C6A6:  LDA $8E         ; Matrix A
         STA $0600       ; Set for airship
         STZ $07C2       ; Matrix B: 0
         STZ $0984       ; Matrix C: 0

; Fork: Scroll clouds
C3C6BF:  REP #$20        ; 16-bit A
         DEC $35         ; BG1's X -1
         DEC $B7         ; Center X -1
         LDA $35         ; BG1 X-Pos
         STA $B691       ; To HDMA table
         LDA $37         ; BG1 Y-Pos
         STA $B693       ; To HDMA table
         LDA $B7         ; Center X
         STA $B699       ; To HDMA table
         LDA $B9         ; Center Y
         STA $B69B       ; To HDMA table
         SEP #$21        ; 8-bit A; requeue
         RTS

; Set to fade credits
C3C6DC:  JSR C3E29E      ; Do big font
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$31E9      ; To OBJ pal 5
         LDX #C310F4     ; Black palette
         JMP slow4       ; Do small font

; Set to fade in credits to white and blue
C3C703:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$9754      ; C2/9754
         JSR slow4       ; Do big font
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$31E9      ; To OBJ pal 5
         LDX #$974C      ; C2/974C
         JMP slow4       ; Do small font

; Set to fade in credits to dark blue
C3C72A:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$9744      ; C2/9744
         JSR slow4       ; Do big font
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$31E9      ; To OBJ pal 5
         LDX #$973C      ; C2/973C
         JMP slow4       ; Do small font

; Load non-text sprite colors for Mode 7 scene
C3C751:  LDX #$97F4      ; C2/97F4
         LDY #$3149      ; To OBJ pal 0
         JSR C30F8E      ; Do balloon's
         LDX #$9794      ; C2/9794
         LDY #$3169      ; To OBJ pal 1
         JSR C30F8E      ; Do airships'
         LDX #$97B4      ; C2/97B4
         LDY #$3189      ; To OBJ pal 2
         JSR C30F8E      ; Do boat's
         LDX #$97D4      ; C2/97D4
         LDY #$31A9      ; To OBJ pal 3
         JSR C30F8E      ; Do cockpit's
         LDX #$9834      ; C2/9834
         LDY #$3209      ; To OBJ pal 6
         JSR C30F8E      ; Do gray birds'
         LDX #$9814      ; C2/9814
         LDY #$3229      ; To OBJ pal 7
         JMP C30F8E      ; Do spray's

; 09: Start aerial-view airship scene
C3C794:  JSR C3C5DC      ; Blue text: Y
         JSL $D4CED7     ; Init registers
         JSR C3D522      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         JSR C3C751      ; Load OBJ colors
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load cloud colors
         LDY #$8A70      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue cloud anim
         JSR C3D983      ; Build text OAM
         LDY #C3D7CB     ; C3/D7CB
         JSR qanim2      ; Queue credits
         JSR C3D2A0      ; Queue M7 handler
         INC $26         ; Next: C3/C7D2
         LDY #$03C0      ; Frames: 960
         STY $20         ; Set plane delay
         JMP C3C66C      ; Queue fade-in

; 0A: Show aerial-view airship and its shadow
C3C7D2:  LDY $20         ; Delay expired?
         BNE C3C868      ; Exit if not
         INC $26         ; Next: C3/C7E1
         LDY #$0870      ; Frames: 2160
         STY $20         ; Set fade delay
         BRA C3C802      ; Create sprites

; 0B: Fade screen to white
C3C7E1:  LDY $20         ; Delay expired?
         BNE C3C868      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Black out
         LDA #$78        ; Frames: 120
         STA $20         ; Set fade delay
         LDA #$C3        ; Bank: C3
         STA $ED         ; Set src HB
         LDY #$30A9      ; To BG pal 3
         LDX #C310D4     ; White palette
         JMP slow2       ; Whiten clouds

; Create aerial-view airship and its shadow
C3C802:  LDA #$C2        ; Anim ptr HB
         LDY #$8CDC      ; Anim ptr LBs
         LDX #$A0F8      ; Pos: 248, 160
         JSR C3C846      ; Create airship
         JSR C3C84F      ; Set spd, timer
         LDY #C3DE84     ; C3/DE84
         JSR qanim3      ; Queue shadow fn
         JSR C3C84F      ; Set spd, timer
         PEA $B0F8       ; Pos: 248, 176
         PEA $8CF0       ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3E9DX      ; Set shadow's

; Queue linearly moving temporary sprite
C3C846:  PHX             ; Save position
         PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3DE84     ; C3/DE84
         JSR qanim1      ; Queue OAM fn
         JMP C3E9DX      ; Set pos, ptr

; Initialize data for aerial-view airship or its shadow
C3C84F:  REP #$20        ; 16-bit A
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set sprite's
         LDA #$FFE0      ; V-Spd: -0.125 px
         STA $7E3549,X   ; Set sprite's
         LDA #$0400      ; Frames: 1024
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
C3C868:  RTS

; 02: Show aerial-view panning clouds
C3C869:  JSR C3C87E      ; Load map, etc.
         LDY #$00F0      ; Frames: 240
         STY $20         ; Set fade delay
         LDY #$8B3C      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue cloud anim
         INC $26         ; Next: Fade-out
         JMP C3C66C      ; Queue fade-in

; Initialize data for spinning or panning clouds
C3C87E:  JSL $D4CED7     ; Init registers
         JSR C3D522      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         JSR C3C751      ; Load OBJ colors
         JSR C3D15C      ; Make text black
         LDY #$0200      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$F000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D173      ; Load cloud colors
         JMP C3D2A0      ; Queue M7 handler

; 03: Wait before fading screen
C3C8A6:  LDY $20         ; Delay expired?
         BNE C3C8AC      ; Exit if not
         STZ $26         ; Next: Fade-out
C3C8AC:  RTS

; 04: Show spinning clouds
C3C8AD:  JSR C3C87E      ; Load map, etc.
         LDY #$8000      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$8000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         LDY #$0078      ; Frames: 120
         STY $20         ; Set fade delay
         LDY #$8B42      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue cloud anim
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         JMP C3C66C      ; Queue fade-in

; 0C: Start boat scene
C3C8D1:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSR C3D5AA      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         LDY #$1000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load BG1 colors
         JSR C3C751      ; Load OBJ colors
         LDY #$8AD9      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue sea anim
         JSR C3CAC7      ; Create birds
         JSR C3D999      ; Build text OAM
         LDY #C3D819     ; C3/D819
         JSR qanim2      ; Queue credits
         JSR C3D2A0      ; Queue M7 handler
         LDY #$0438      ; Delay: 1080
         STY $20         ; Set boat OBJ's
         INC $26         ; Next: C3/C917
         JMP C3C66C      ; Queue fade-in

; 0D: Show boat sprite
C3C917:  LDY $20         ; Delay expired?
         BNE C3C925      ; Exit if not
         JSR C3C94E      ; Create boat
         STZ $26         ; Next: Fade-out
         LDY #$02D0      ; Frames: 720
         STY $20         ; Set fade delay
C3C925:  RTS

; Create boat sprite
C3C94E:  LDA #$CF        ; Anim ptr HB
         LDY #$F809      ; Anim ptr LBs
         LDX #$50F8      ; Pos: 248, 80
         JSR C3E9D2      ; Create L-Half
         REP #$20        ; 16-bit A
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set L-Half's
         SEP #$20        ; 8-bit A
         LDY #C3C9A2     ; C3/C9A2
         JSR qanim1      ; Queue R-Half
         REP #$20        ; 16-bit A
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set R-Half's
         SEP #$20        ; 8-bit A
         PEA $50F8       ; Pos: 248, 80
         PEA $F7FD       ; Anim ptr LBs
         LDA #$CF        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3E9DX      ; Set R-Half's

; Animate boat's right half
C3C9A2:  BNE C3C9BC      ; If mode 1

; Mode 0: Initialize timers
C3C9AA:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0040      ; Frames: 64
         STA $3349,X     ; Set show delay
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3C9BC:  LDY $3349,X     ; Delay expired?
         BNE C3C9C8      ; Branch if not
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3C9C8:  JSR C3CFE5      ; Delay -1
         SEC             ; Set to requeue
         RTS

; 10: Start skimming airship scene
C3C9CD:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSR C3D5DA      ; Upload GFX, map
         JSR C3CA71      ; Get sky; init M7
         JSR C3D38C      ; Queue gradient
         JSR C3D36F      ; HDMA: Color math
         JSR C3C751      ; Load OBJ colors
         LDY #$0028      ; Y: 40
         STY $3B         ; Set BG2 Y-Pos
         LDY #$FF6D      ; Mod index: 109
         STY $C3         ; Set matrices'
         LDY #$034C      ; Vertical angle
         STY $C7         ; Set for sea
         LDY #$FD00      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3CAFD      ; Create birds
         LDY #C3CBC6     ; C3/CBC6
         JSR qanim2      ; Queue airship
         LDA #$C2        ; Anim ptr HB
         LDY #$8BB1      ; Anim ptr LBs
         JSR anm_st      ; Set airship's
;        LDA #$78        ; X: 120
;        STA $7E33CA,X   ; C3/CBDB...
;        LDA #$58        ; Base Y/2: 88
;        STA $7E344A,X   ; C3/CBE0...
         LDA #$C2        ; Anim ptr HB
         LDY #$8BEC      ; Anim ptr LBs
         LDX #$8080      ; Pos: 128, 128
         JSR C3E9D2      ; Create shadow
         JSR C3D173      ; Load sea colors
         JSR C3D9AF      ; Build text OAM
         LDY #C3D849     ; C3/D849
         JSR qanim2      ; Queue credits
         LDY #$8B36      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue sea anim
         LDY #C3CAA2     ; C3/CAA2
         JSR qanim3      ; Set to pan sky
         JSR C3D2A0      ; Queue M7 handler
         INC $26         ; Next: Late bird
         LDY #$04B0      ; Frames: 1200
         STY $20         ; Set bird's delay
         JMP C3C66C      ; Queue fade-in

; Load cloudy sky graphics data, exclude sky from Mode 7
C3CA71:  JSR C3D3E6      ; Reset M7 vars
         JSR C3D4D3      ; Load GFX, map
         JSR C3D34B      ; Set up M7 HDMA
         JSR C3D15C      ; Make text black
C3CA80:  LDY #$3049      ; To BG pal 0
         LDX #$953C      ; C2/953C
         JMP C30F8E      ; Load sky colors

; 11: Show swooping bird
C3CA8C:  LDY $20         ; Delay expired?
         BNE C3CAAE      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0708      ; Frames: 1800
         STY $20         ; Set fade delay
         LDY #C3CC79     ; C3/CC79
         JMP qanim1      ; Queue bird OAM

; Scroll sky eastward
C3CAA2:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         BCS C3CAAE      ; Exit if so
         REP #$20        ; 16-bit A
         DEC $39         ; BG2 camera -1
C3CAAE:  SEC             ; Set to requeue
         RTS

; Scroll sky westward
C3CAB0:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         BCS C3CABC      ; Exit if so
         REP #$20        ; 16-bit A
         INC $39         ; BG2 camera +1
C3CABC:  SEC             ; Set to requeue
         RTS

; Create birds for boat scene
C3CAC7:  LDX #$F7B5      ; Source LBs
         LDA #$CF        ; Source HB
         BRA bird6       ; Create birds

; Create oscillating birds around skimming airship
C3CAFD:  LDX #$F7CD      ; Source LBs
         LDA #$CF        ; Source HB
         BRA bird6       ; Create birds

; Create birds above grassfield
C3CB2E:  LDX #$F7E5      ; Source LBs
         LDA #$CF        ; Source HB
bird6:   STX $FD         ; Set src LBs
         STA $FF         ; Set src HB
         LDY $00         ; ROM index: 0
.loop    PHY             ; Save ROM index
         LDY #C3CB68     ; C3/CB68
         JSR qanim2      ; Queue anim fn
         PLY             ; ROM index
         REP #$20        ; 16-bit A
         LDA [$FD],Y     ; Anim table ptr
         INY             ; ROM index +1
         INY             ; ROM index +1
         STA $7E32C9,X   ; Set bird's
         SEP #$20        ; 8-bit A
         LDA [$FD],Y     ; Base X / 2
         INY             ; ROM index +1
         STA $7E34CA,X   ; Set bird's
         LDA [$FD],Y     ; Base Y
         INY             ; ROM index +1
         STA $7E344A,X   ; Set bird's
         LDA $26         ; Current scene
         CMP #$0C        ; Boat scene?
         BNE .skip       ; Branch if not
         JSR C3EA6C      ; Follow BG1: Y
.skip    CPY #$0018      ; Done 6 birds?
         BNE .loop       ; Loop if not
         RTS

; Animate oscillating bird
C3CB68:  BNE C3CB87      ; If mode 1

; Mode 0: Initialize data
C3CB70:  INC $3649,X     ; Mode +1
         LDA.L C3CB68,X  ; X-Mod index
         STA $3349,X     ; Set bird's
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3CB87:  JSR C3CB94      ; Init X position
         INC $3349,X     ; X-Mod index +1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Update bird's back-and-forth motion (range: -8 to +7)
C3CB94:  LDA $3349,X     ; X-Mod index
         JSR C3DE76      ; Fract X mod
         PHA             ; Set original
;        STA $E0         ; Set current
;        LDA $E0         ; Shift right?
         BPL C3CBA8      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3CBA8:  STA $E0         ; Save changes
         PLA             ; Shift right?
         BPL C3CBB7      ; Branch if so
         JSR C3CC31      ; Modifier / 16
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3CBBA      ; Skip a line
C3CBB7:  JSR C3CC31      ; Modifier / 16
C3CBBA:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $34C9,X     ; Add base X/2
         STA $33C9,X     ; Init bird's X
         SEP #$20        ; 8-bit A
         RTS

; Animate skimming airship
C3CBC6:  BNE C3CBE6      ; If mode 1

; Mode 0: Initialize data
C3CBCE:  INC $3649,X     ; Mode +1
         STZ $3349,X     ; Anim timer: 0
         LDA #$78        ; X: 120
         STA $33CA,X     ; Set sprite's
         LDA #$20        ; Base Y/2: 32
         STA $354A,X     ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3CBE6:  JSR C3CBFF      ; Init Y position
         INC $3349,X     ; Anim timer +1
         LDA $3349,X     ; Anim timer
         CMP #$38        ; Within 56-255?
         BCS C3CBFA      ; Branch if so
         JSR C3CC38      ; Create spray
C3CBFA:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Update airship's up-and-down motion (range: -8 to +7)
C3CBFF:  LDA $3349,X     ; Anim timer
         REP #$20        ; 16-bit A
         JSR C3DE7A      ; Fract Y mod
         PHA             ; Set original
;        STA $E0         ; Set current
;        LDA $E0         ; Shift down?
         BPL C3CC13      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3CC13:  STA $E0         ; Save changes
         PLA             ; Shift down?
         BPL C3CC22      ; Branch if so
         JSR C3CC31      ; Modifier / 16
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3CC25      ; Skip a line
C3CC22:  JSR C3CC31      ; Modifier / 16
C3CC25:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add base Y
         STA $3449,X     ; Init ship's Y
         SEP #$20        ; 8-bit A
         RTS

; Divide sprite's position modifier by 16
C3CC31:  LDA $E0         ; Y modifier
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; ÷16
         RTS

; Create water spray
C3CC38:  LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3CC78      ; Exit if 1-3
         PHB             ; Save DB
         LDA #$C2        ; Anim ptr HB
         LDY #$8D0B      ; Anim ptr LBs
         LDX #$7C7E      ; Pos: 126, 124
         JSR C3C846      ; Create sprite
         PLB             ; Restore DB
         LDA #$18        ; Frames: 24
         STA $3349,X     ; Set hide delay
         REP #$20        ; 16-bit A
         LDA #$0100      ; H-Spd: +1 px
         STA $34C9,X     ; Set sprite's
         LDA #$FF80      ; V-Spd: -0.5 px
         STA $3549,X     ; Set sprite's
C3CC78:  RTS

; Animate swooping bird
C3CC79:  BNE C3CCA8      ; If mode 1

; Mode 0: Initialize sprite
C3CC81:  INC $3649,X     ; Mode +1
;        STZ $34CA,X     ; Base X HB: 0
;        STZ $354A,X     ; Base Y HB: 0
         LDA #$CF        ; Anim ptr HB
         LDY #$F772      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDA #$10        ; Pos index: 16
         STA $3349,X     ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3CCA8:  LDA $33CA,X     ; X position
         CMP #$08        ; Under 8?
         BCS C3CCB3      ; Display if not
         CLC             ; Set to dequeue
         RTS

; Fork: Set X position
C3CCB3:  LDA $3349,X     ; Position index
         JSR C3DE76      ; Fractional X
         ASL A           ; Double it
         LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $34C9,X     ; Add base X
         STA $33C9,X     ; Set bird's X

; Fork: Set Y position
C3CCE2:  LDA $3349,X     ; Position index
         JSR C3DE7A      ; Fractional Y
         LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add base Y
         STA $3449,X     ; Set bird's Y
         INC $3349,X     ; Pos index +1
         JMP oamsec      ; Set OAM; requeue

; 14: Start frontview airship scene
C3CD17:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSL C3D573      ; Upload GFX, map
         JSR C3CA71      ; Get sky; init M7
         JSR C3D38C      ; Queue gradient
         JSR C3D36F      ; HDMA: Color math
         JSR C3C751      ; Load OBJ colors
         LDY #$0028      ; Y: 40
         STY $3B         ; Set BG2 Y-Pos
         LDY #$FFCD      ; Mod index: 205
         STY $C3         ; Set matrices'
         LDY #$030B      ; Vertical angle
         STY $C7         ; Set for field
         LDY #$F000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D173      ; Load BG1 colors
         JSR C3CB2E      ; Create birds
         LDA #$C2        ; Anim ptr HB
         LDY #$8C25      ; Anim ptr LBs
         LDX #$5878      ; Pos: 120, 88
         JSR C3CFDC      ; Create airship
         LDY #$8B39      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue field anim
         JSR C3D9C5      ; Build text OAM
         LDY #C3D897     ; C3/D897
         JSR qanim2      ; Queue credits
         LDY #C3CAB0     ; C3/CAB0
         JSR qanim3      ; Set to pan sky
         JSR C3D2A0      ; Queue M7 handler
         INC $26         ; Next: Late flock
         LDY #$04B0      ; Frames: 1200
         STY $20         ; Set flock delay
         JMP C3C66C      ; Queue fade-in

; 15: Show late bird flock
C3CDA0:  LDY $20         ; Delay expired?
         BNE C3CE32      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0708      ; Frames: 1800
         STY $20         ; Set fade delay
         LDY #$5000      ; Pos: 0, 80
         JSR C3CD97      ; Create bird 1
         LDY #$4018      ; Pos: 24, 64
         JSR C3CD97      ; Create bird 2
         LDY #$6840      ; Pos: 64, 104
         JSR C3CD97      ; Create bird 3
         LDY #$4810      ; Pos: 16, 72
;        BRA C3CD97      ; Create bird 4

; Create bird from late flock
C3CD97:  PHY             ; Save position
         LDY #C3CDEA     ; C3/CDEA
         JSR qanim2      ; Queue anim fn
         JMP C3E9DY      ; Set position

; Animate bird from late flock
C3CDEA:  CMP #$10        ; Mode 8?
         BEQ C3CE33      ; Branch if so
         DEC A           ; Mode 0?
         BPL C3CE1F      ; Branch if not

; Mode 0: Initialize data
C3CE00:  LDA #$CF        ; Anim ptr HB
         LDY #$F74F      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         INC $3649,X     ; Mode +1
;        STZ $35C9,X     ; Course: NE
         JSR C3CE43      ; Define path
         JSR C3120_      ; Set pose timer

; Modes 1-7: Alter course
C3CE1F:  LDY $3349,X     ; Mode expired?
         BNE C3CE2B      ; Branch if not
         JSR C3CE43      ; Alter path
C3CE2B:  JSR C3CFE5      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
C3CE32:  RTS

; Mode 8: Delete if set to wrap horizontally
C3CE33:  JSR C3DEC0      ; Scroll & OAM
         LDA $33CA,X     ; Bird's X
         BNE C3CE41      ; Requeue if > 0
         CLC             ; Set to dequeue
         RTS             ; Exit
C3CE41:  SEC             ; Set to requeue
         RTS

; Alter course of bird from late flock
C3CE43:  INC $3649,X     ; Mode +1
         TXY             ; Queue index
         TDC             ; Clear A
         LDA $35C9,X     ; Path index
         INC $35C9,X     ; Orig Index +1
         ASL A           ; Path index x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3CE6E,X  ; H-Speed
         STA $34C9,Y     ; Set bird's
         LDA.L C3CE70,X  ; V-Speed
         STA $3549,Y     ; Set bird's
         LDA.L C3CE72,X  ; Path timer
         STA $3349,Y     ; Set bird's
         SEP #$20        ; 8-bit A
         RTS

; Late bird flock's course
C3CE6E:  dw $0020        ; H-Speed: +0.125 px
         dw $0020        ; H-Speed: +0.125 px
         dw $0020        ; H-Speed: +0.125 px
         dw $0010        ; H-Speed: +0.0625 px
         dw $FFE0        ; H-Speed: -0.125 px
         dw $FFC0        ; H-Speed: -0.25 px
         dw $FF80        ; H-Speed: -0.5 px
C3CE70:  dw $FFF0        ; V-Speed: -0.0625 px
         dw $0000        ; V-Speed: 0
         dw $0020        ; V-Speed: +0.125 px
         dw $0040        ; V-Speed: +0.25 px
         dw $0040        ; V-Speed: +0.25 px
         dw $0040        ; V-Speed: +0.25 px
         dw $0080        ; V-Speed: +0.5 px
C3CE72:  dw $0384        ; Frames: 900
         dw $003C        ; Frames: 60
         dw $003C        ; Frames: 60
         dw $003C        ; Frames: 60
         dw $003C        ; Frames: 60
         dw $00B4        ; Frames: 180
         dw $00B4        ; Frames: 180

; 18: Start aerial-view plains scene
C3CEA6:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSL C3D573      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         LDY #$1800      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load BG1 colors
         LDY #$8AFA      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue field anim
         JSR C3D9DB      ; Build text OAM
         LDY #C3D8E5     ; C3/D8E5
         JSR qanim2      ; Queue credits
         JSR C3D2A0      ; Queue M7 handler
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0E10      ; Frames: 3600
         STY $20         ; Set fade delay
         JMP C3C66C      ; Queue fade-in

; 1C: Start rearview airship scene
C3CEEC:  JSL $D4CED7     ; Init registers
         JSL C3D573      ; Upload GFX, map
         JSR C3D144      ; Upload balloon
         JSR C3CA71      ; Get sky; init M7
         JSR C3D38C      ; Queue gradient
         JSR C3D36F      ; HDMA: Color math
         LDY #$0100      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$02DC      ; Vertical angle
         STY $C7         ; Set for field
         JSR C3DDD2      ; Make matrix tbl
         LDY #$0010      ; Y: 16
         STY $3B         ; Set BG2 Y-Pos
         JSR C3D15C      ; Make text black
         JSR C3C751      ; Load OBJ colors
         JSR C3D173      ; Load BG1 colors
         JSR C3D9E6      ; Build text OAM
         LDY #C3D933     ; C3/D933
         JSR qanim2      ; Queue credits
         LDY #C3CF9A     ; C3/CF9A
         JSR qanim0      ; Queue BG scroll
         LDX #$1444      ; Pos: 68, 20
         JSR C3CFB2      ; Create SW rotor
         LDX #$14AC      ; Pos: 172, 20
         JSR C3CFC7      ; Create SE rotor
         LDX #$E860      ; Pos: 96, 232
         JSR C3CFB2      ; Create NW rotor
         LDX #$E890      ; Pos: 144, 232
         JSR C3CFC7      ; Create NE rotor
         LDA #$C2        ; Anim ptr HB
         LDY #$8C60      ; Anim ptr LBs
         LDX #$F848      ; Pos: 72, 248
         JSR C3CFDC      ; Create airship
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$08AC      ; Frames: 2220
         STY $20         ; Set fade delay
         JMP C3C66C      ; Queue fade-in

; Scroll field and sky for rearview airship scene
C3CF9A:  LDA $23         ; NMI count
         AND #$7F        ; 0 or 128?
         BNE C3CFA2      ; Branch if not
         INC $3B         ; Shift sky up
C3CFA2:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         BCS C3CFB0      ; Exit if so
         REP #$20        ; 16-bit A
         DEC $B9         ; Center Y -1
         DEC $37         ; Move field down
C3CFB0:  SEC             ; Set to requeue
         RTS

; Create NW or SW airship rotor
C3CFB2:  LDA #$C2        ; Anim ptr HB
         LDY #$8D3E      ; Anim ptr LBs
         BRA C3CFDC      ; Branch below

; Create NE or SE airship rotor
C3CFC7:  LDA #$C2        ; Anim ptr HB
         LDY #$8D91      ; Anim ptr LBs

; Create frontview or rearview airship or rotor
C3CFDC:  PHX             ; Save position
         PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3CFF8     ; C3/CFF8
         JSR qanim2      ; Queue OAM fn
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         PLA             ; X position
         STA $7E33CA,X   ; Set rotor's
         PLA             ; Y position
         STA $7E354A,X   ; Set rotor's
         RTS

; Decrease sprite's animation mode timer
C3CFE5:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         RTS

; Animate frontview or rearview airship or rotor
C3CFF8:  BNE C3D00B      ; If mode 1

; Mode 0: Initialize timers
C3D000:  JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         STZ $3349,X     ; Anim timer: 0

; Mode 1: Sustain sprite
C3D00B:  JSR C3CBFF      ; Set altitute
         INC $3349,X     ; Anim timer +1
oamsec:  JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Load colors for blue sky and non-sprite airships
C3D018:  LDY #$3049      ; To BG pal 0
         LDX #$959C      ; C2/959C
         JSR C30F8E      ; Load fill color
         LDY #$3069      ; To BG pal 1
         LDX #$959C      ; C2/959C
         JMP C30F8E      ; Load the rest

; 20: Start final airship scene
C3D02F:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         LDA #$80        ; Map wraps: No
         STA $211A       ; Set M7 settings
         JSR C3D60A      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CE55     ; HDMA: MS desig
;        LDY #$31C9      ; To OBJ pal 4
;        LDX #$9754      ; C2/9754
;        JSR C30F8E      ; No text...
;        LDY #$31E9      ; To OBJ pal 5
;        LDX #$974C      ; C2/974C
;        JSR C30F8E      ; No text...
;        JSR C3D173      ; No field...
         JSR C3D018      ; Load BG colors
         LDY #$0001      ; Zoom-out: 1
         STY $BB         ; Set matrix A
         STY $C1         ; Set matrix D
         LDY #$0008      ; X: 8
         STY $B7         ; Set center X
         LDY #$0018      ; Y: 24
         STY $B9         ; Set center Y
         LDY #$FFD8      ; X: -40
         STY $35         ; Set BG1 X-Pos
         LDY #$FFD0      ; Y: -48
         STY $37         ; Set BG1 Y-Pos
         LDY #C3D122     ; C3/D122
         JSR qanim0      ; Queue zoom-out
         INC $26         ; Next: C3/D096
         LDY #$0096      ; Frames: 150
         STY $20         ; Set fade delay
         LDY #C3D0A8     ; C3/D0A8
         JSR qanim0      ; Queue rotor fn
         JMP C3C66C      ; Queue fade-in

; 21: Fade final airship
C3D096:  LDY $20         ; Delay expired?
         BNE C3D0CF      ; Exit if not
         STZ $26         ; Next: Fade-out
         LDA #$78        ; Frames: 120
         STA $20         ; Set fade timer
         JSR C3E16B      ; Fade BG pal 1+2
         JMP C3E241      ; Fade BG pal 0

; Animate final airship's rotors
C3D0A8:  REP #$20        ; 16-bit A
         LDA $23         ; NMI count
         LSR A           ; Odd value?
         LDA #$4F51      ; Tiles: 79, 81
         BCS C3D0BF      ; If odd count
         LDA #$5A59      ; Tiles: 90, 89
C3D0BF:  STA $9849       ; Set rotor tiles
         SEP #$20        ; 8-bit A

; Fork: Set to refresh rotors
C3D0D0:  LDY #$0283      ; L-Rotor adr
         STY $14         ; Set VRAM ptr1
         LDY #$9849      ; 7E/9849
         STY $16         ; Set src1 LBs
         LDY #$0206      ; R-Rotor adr
         STY $1B         ; Set VRAM ptr2
         LDY #$984A      ; 7E/984A
         STY $1D         ; Set src2 LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src1 HB
         STA $1F         ; Set src2 HB
         LDY #$0001      ; Bytes: 1
         STY $12         ; Set src1 size
         STY $19         ; Set src2 size
         SEC             ; Set to requeue
C3D0CF:  RTS

; Animate sideview airship's rotors
C3D0F2:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         LDA #$58        ; Tile: 88
         BCS C3D105      ; If odd count
         LDA #$34        ; Tile: 52
C3D105:  STA $9849       ; Set rotors'

; Fork: Set to refresh rotors
C3D10E:  LDY #$0892      ; $0892
         STY $14         ; Set VRAM ptr
         LDY #$9849      ; 7E/9849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0001      ; Bytes: 1
         STY $12         ; Set data size
         SEC             ; Set to requeue
         RTS

; Process queued zoom-out for final airship scene
C3D122:  LDA $23         ; NMI count
         AND #$07        ; Now 0-7
         REP #$20        ; 16-bit A
         BNE C3D137      ; Branch if > 0
         INC $B7         ; M7 center X +1
         INC $B9         ; M7 center Y +1
C3D137:  INC $BB         ; Matrix A +1
         INC $BB         ; Matrix A +1
         INC $C1         ; Matrix D +1
         INC $C1         ; Matrix D +1
         SEC             ; Set to requeue
         RTS

; Upload rearview airship's balloon graphics
C3D144:  LDY #$D7BA      ; 7E/D7BA
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDX #$0580      ; Bytes: 1408
         LDY #$6C00      ; VRAM pointer
         JMP C3DDB_      ; Upload data

; Initialize credits' colors to black for fade-in
C3D15C:  LDY #$31C9      ; To OBJ pal 4
         JSR black       ; Do big font
         LDY #$31E9      ; To OBJ pal 5
         JMP black       ; Do small font

; Load BG1 palettes for credits scenes
C3D173: ;LDY #$3069      ; To BG pal 1
;        LDX #$95BC      ; C2/95BC
;        JSR C30F8E      ; C3/D02B...
         LDY #$3089      ; To BG pal 2
         LDX #$95DC      ; C2/95DC
         JSR C30F8E      ; Do sea
         LDY #$30A9      ; To BG pal 3
         LDX #$95FC      ; C2/95FC
         JSR C30F8E      ; Do clouds
         LDY #$30C9      ; To BG pal 4
         LDX #$961C      ; C2/961C
         JSR C30F8E      ; Do trees
         LDY #$3109      ; To BG pal 6
         LDX #$963C      ; C2/963C
         JSR C30F8E      ; Do lake
         LDY #$3129      ; To BG pal 7
         LDX #$965C      ; C2/965C
         JMP C30F8E      ; Do grass

; Scroll actor's pseudonym down
C3D1B6:  LDY $CF         ; Scroll timer
         CPY $64         ; At endpoint?
         BEQ C3D1CA      ; Dequeue if so
         LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3D1C8      ; Exit if 1-3
         REP #$20        ; 16-bit A
         DEC $3F         ; BG3 camera up
C3D1C8:  SEC             ; Set to requeue
         RTS             ; Exit
C3D1CA:  CLC             ; Set to dequeue
         RTS

; Process queued field fade-in
C3D1CC:  BNE C3D1E3      ; If mode 1

; Mode 0: Initialize brightness
C3D1D4:  INC $3649,X     ; Mode +1
         LDA #$01        ; BRT: 1 and ON
         STA $344A,X     ; Set next BRT
         LDA #$0F        ; Frames: 15
         STA $3349,X     ; Set timer

; Mode 1: Increase brightness
C3D1E3:  LDA $3349,X     ; Timer expired?
         BEQ C3D1F7      ; Finalize if so
         LDA $344A,X     ; Next brightness
         STA $44         ; Set as current
         INC $344A,X     ; Next BRT +1
         DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3D1F7:  LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Process queued field fade-out
C3D1FD:  BNE C3D20F      ; If mode 1

; Mode 0: Initialize brightness
C3D205:  INC $3649,X     ; Mode +1
         LDA #$0F        ; BRT: 15 and ON
         STA $33CA,X     ; Set next BRT

; Mode 1: Decrease brightness
C3D20F:  LDY $20         ; Timer expired?
         BEQ C3D21F      ; Finalize if so
         LDA $33CA,X     ; Next brightness
         STA $44         ; Set as current
         DEC $33CA,X     ; Next BRT -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3D21F:  LDA #$80        ; BRT: 0 and OFF
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Queue Mode 7 animation script loading
C3D225:  PHA             ; Save ptr HB
         PHY             ; Save ptr LBs
         LDY #C3D23F     ; C3/D23F
         JSR qanim1      ; Queue anim fn
         PLY             ; Anim ptr LBs
         PLA             ; Anim ptr HB
         JMP anm_st      ; Put in queue

; Load parameters for Mode 7 animation
C3D23F:  BNE C3D24F      ; If mode 1

; Mode 0: Initialize sequence timer
C3D247:  JSR C31206      ; Set anim timer
         INC $3649,X     ; Mode +1

; Mode 1: Load animation flags
C3D24F:  JSR C31227      ; Anim timer -1
         TDC             ; Clear A
         LDA $36C9,X     ; Anim index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Anim flags
         STA $04         ; Set as current
         SEC             ; Set to requeue
         RTS

; Refresh Mode 7 registers (NMI)
C3D263:  LDA $BB         ; Matrix A LB
         STA $211B       ; To register
         LDA $BC         ; Matrix A HB
         STA $211B       ; To register
         LDA $BD         ; Matrix B LB
         STA $211C       ; To register
         LDA $BE         ; Matrix B HB
         STA $211C       ; To register
         LDA $BF         ; Matrix C LB
         STA $211D       ; To register
         LDA $C0         ; Matrix C HB
         STA $211D       ; To register
         LDA $C1         ; Matrix D LB
         STA $211E       ; To register
         LDA $C2         ; Matrix D HB
         STA $211E       ; To register
         LDA $B7         ; Center X LB
         STA $211F       ; To register
         LDA $B8         ; Center X HB
         STA $211F       ; To register
         LDA $B9         ; Center Y LB
         STA $2120       ; To register
         LDA $BA         ; Center Y HB
         STA $2120       ; To register
         RTS

; Queue Mode 7 animation script decoding
C3D2A0:  LDY #C3D2A9     ; C3/D2A9
         JMP qanim0      ; Queue anim fn

; Decode parameters for Mode 7 animation
C3D2A9:  LDA $04         ; Anim flags
         BIT #$10        ; Tilt right?
         BEQ C3D2B7      ; Skip if not
         REP #$20        ; 16-bit A
         INC $C3         ; Mod index +1
         SEP #$20        ; 8-bit A
;        INC $59         ; No use...

; Fork: Rotate counterclockwise
C3D2B7:  LDA $04         ; Anim flags
         BIT #$20        ; Tilt left?
         BEQ C3D2C5      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $C3         ; Mod index -1
         SEP #$20        ; 8-bit A
;        DEC $59         ; No use...

; Fork: Rotate forward
C3D2C5:  LDA $04         ; Anim flags
         ASL A           ; Tilt up?
         BPL C3D2D1      ; Skip if not
         REP #$20        ; 16-bit A
         INC $C7         ; Matrix mod +1
         SEP #$20        ; 8-bit A

; Fork: Rotate backward
C3D2D1:  LDA $05         ; Anim flags
         ASL A           ; Tilt down?
         BPL C3D2DD      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $C7         ; Matrix mod -1
         SEP #$20        ; 8-bit A

; Fork: Zoom in
C3D2DD:  LDA $04         ; Anim flags
;        BIT #$80        ; Inc divisor?
         BPL C3D2E5      ; Skip if not
         INC $C6         ; Divisor +1

; Fork: Zoom out
C3D2E5:  LDA $05         ; Anim flags
;        BIT #$80        ; Dec divisor?
         BPL C3D2ED      ; Skip if not
         DEC $C6         ; Divisor -1

; Fork: Scroll southward
C3D2ED:  LDA $05         ; Anim flags
         BIT #$08        ; Scroll down?
         BEQ C3D2FB      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $B9         ; Center Y -1
         DEC $37         ; BG1 Y-Pos -1
         SEP #$20        ; 8-bit A

; Fork: Scroll northward
C3D2FB:  LDA $05         ; Anim flags
         BIT #$04        ; Scroll up?
         BEQ C3D309      ; Skip if not
         REP #$20        ; 16-bit A
         INC $B9         ; Center Y +1
         INC $37         ; BG1 Y-Pos +1
         SEP #$20        ; 8-bit A

; Fork: Scroll eastward
C3D309:  LDA $05         ; Anim flags
         BIT #$02        ; Scroll right?
         BEQ C3D317      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $B7         ; Center X -1
         DEC $35         ; BG1 X-Pos -1
         SEP #$20        ; 8-bit A

; Fork: Scroll westward
C3D317:  LDA $05         ; Anim flags
         LSR A           ; Scroll left?
         BCC C3D325      ; Skip if not
         REP #$20        ; 16-bit A
         INC $B7         ; Center X +1
         INC $35         ; BG1 X-Pos +1
         SEP #$20        ; 8-bit A

; Fork: Build Mode 7 matrix tables
C3D325:  JSR C3D338      ; Cap center X/Y
         REP #$20        ; 16-bit A
         LDA $04         ; Anim flags
         AND #$F0FF      ; Only scrolling?
         SEP #$20        ; 8-bit A
         BEQ C3D336      ; Exit if so
         JSR C3DDD2      ; Build tables
C3D336:  SEC             ; Set to requeue
         RTS

; Keep Mode 7 center X and Y within boundaries
C3D338:  REP #$20        ; 16-bit A
         LDA #$E000      ; Bits to discard
         TRB $B7         ; Cap center X
         TRB $B9         ; Cap center Y
         RTS

; Configure Mode 7 not to apply to cloudy sky
C3D34B:  JSL $D4CB8F     ; HDMA: Matrices
         STZ $4310       ; 1Rx1B to PPU
         LDA #$05        ; $2105
         STA $4311       ; To BG mode
         LDY #C3D36A     ; C3/D36A
         STY $4312       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4314       ; Set src HB
         LDA #$02        ; Channel: 1
         TSB $43         ; Queue HDMA-1
         RTS

; BG mode and tile size per scanline
C3D36A:  db $47,$01      ; Mode 1, 8x8 tiles
         db $01,$07      ; Mode 7
         db $00          ; End

; Set color addition and math for field and for cloudy sky
C3D36F:  LDA #$01        ; 2Rx1B to PPU
         STA $4330       ; Set DMA mode
         LDA #$30        ; $2130, $2131
         STA $4331       ; To color regs
         LDY #C3D3A7     ; C3/D3A7
         STY $4332       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4334       ; Set src HB
         LDA #$08        ; Channel: 3
         TSB $43         ; Queue HDMA-3
         RTS

; Queue gradient effect for field under sky
C3D38C:  STZ $4320       ; 1Rx1B to PPU
         LDA #$32        ; $2132
         STA $4321       ; To fixed color
         LDY #C3D3AE     ; C3/D3AE
         STY $4322       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4324       ; Set src HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Color addition and math per scanline
C3D3A7:  db $47,$80,$41  ; BG1, inside window, half mode
C3D3AA:  db $01,$82,$01  ; BG1, inside window, add subscreen
C3D3AD:  db $00          ; End

; Gradient table for the above
C3D3AE:  db $47,$E0      ; RGB: 0
C3D3B0:  db $01,$ED      ; RGB: 13
C3D3B2:  db $01,$EB      ; RGB: 11
C3D3B4:  db $01,$EA      ; RGB: 10
C3D3B6:  db $02,$E9      ; RGB: 9
C3D3B8:  db $03,$E8      ; RGB: 8
C3D3BA:  db $04,$E7      ; RGB: 7
C3D3BC:  db $05,$E6      ; RGB: 6
C3D3BE:  db $06,$E5      ; RGB: 5
C3D3C0:  db $07,$E4      ; RGB: 4
C3D3C2:  db $08,$E3      ; RGB: 3
C3D3C4:  db $0C,$E2      ; RGB: 2
C3D3C6:  db $0F,$E1      ; RGB: 1
C3D3C8:  db $1E,$E0      ; RGB: 0
C3D3CA:  db $00          ; End

; Reset Mode 7 parameters
C3D3E6:  LDY #$0100      ; 256
         STY $B7         ; Set center X
         LDY #$0080      ; 128
         STY $B9         ; Set center Y
         STY $35         ; Set BG1 X-Pos
;        STZ $58         ; No use...
;        LDA #$40        ; No use...
;        STA $59         ; No use...
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $37         ; BG1 Y-Pos: 0
;        LDY $00         ; Vertical angle
         STY $C7         ; Set for BG1
;        LDY $00         ; Mod index: 0
         STY $C3         ; Set matrices'
         LDY #$0100      ; Base divisor
         STY $C5         ; Set matrices'
         RTS

; Unpack and upload graphics and tilemaps for sideview airship scene
C3D40C:  JSR C3D439      ; Upload font GFX
         JSR C3D6B1      ; Unpack map, GFX
         JSR C3D66B      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D42A      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D66B      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D42A      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for sideview airship scene
C3D42A:  JSR C3D68D      ; Set ptrs loc
         LDX #$FC1A      ; Tiles loc LBs
         LDA #$7E        ; Tiles loc HB
         JMP C3D706      ; Build map

; Unpack and upload font graphics for credits
C3D439:  LDY #$BA00      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Load big font
         JSR C3D497      ; Set as 16x16
         JSR C3D518      ; Src: 7E/C000
         LDX #$0C00      ; Bytes: 3072
         LDY #$7000      ; VRAM pointer
         JSR C3DD86      ; Upload font
         LDY #$87C0      ; C4/87C0
         STY $E7         ; Set src LBs
         LDA #$C4        ; Src HB: C4
         LDX #$0200      ; Bytes: 512
         LDY #$7E00      ; VRAM pointer
         JSR C3DD86      ; Do small font

; Upload period and space character for special thanks
C3D46F:  LDY #$8C10      ; C4/8C10
         STY $E7         ; Set src LBs
         LDA #$C4        ; Src HB: C4
         LDX #$0010      ; Bytes: 16
         LDY #$7FA0      ; VRAM pointer
         JSR C3DD86      ; Upload period
         LDY #$8FB0      ; C4/8FB0
         STY $E7         ; Set src LBs
         LDA #$C4        ; Src HB: C4
         LDX #$0010      ; Bytes: 16
         LDY #$7FB0      ; VRAM pointer
         JMP C3DD86      ; Upload space

; Expand large font graphics to 16x16 for credits
C3D497:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         TAX             ; ROM index: 0
         TXY             ; Dst index: 0
C3D49F:  PHX             ; Save ROM index
         TDC             ; Clear A
         LDA $C29854,X   ; Tile index
         REP #$20        ; 16-bit A
         JSR x16         ; x16
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA #$10        ; Rows: 8
C3D4B2:  PHA             ; Save counter
         LDA $C000,X     ; 8 px, 1 plane
         STA $C400,Y     ; Put in buffer
         INX             ; Src index +1
         INY             ; Dst index +1
         PLA             ; Counter
         DEC A           ; Counter -1
         BNE C3D4B2      ; Loop till zero

; Fork: Blank right-hand 8x8 tile
C3D4BE:  TDC             ; Clear A
         TAX             ; Counter: 0
C3D4C0:  STA $C400,Y     ; Clear a plane
         INY             ; Dst index +1
         INX             ; Counter +1
         CPX #$0010      ; Done 8 rows?
         BNE C3D4C0      ; Loop if not
         PLX             ; ROM index
         INX             ; ROM index +1
         CPX #$0040      ; Done 64 tiles?
         BNE C3D49F      ; Loop if not
         PLB             ; Restore DB
         RTS

; Unpack and upload cloudy sky graphics and tilemap
C3D4D3:  REP #$20        ; 16-bit A
         LDA $EEB206     ; Source LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         LDA $EEB208     ; Source HB
         JSR C3DD61      ; Unpack graphics
         JSR C3D518      ; Src: 7E/C000
         LDX #$1A20      ; Bytes: 6688
         LDY #$4000      ; VRAM pointer
         JSR C3DDB_      ; Upload graphics
         REP #$20        ; 16-bit A
         LDA $EEB209     ; Source LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         LDA $EEB20B     ; Source HB
         JSR C3DD61      ; Unpack tilemap
         LDY #$2000      ; Add: Priority
         STY $ED         ; Set complement
         JSR C3D518      ; Src: 7E/C000
         LDX #$0400      ; Bytes: 1024
         LDY #$5000      ; VRAM pointer
         JMP C3DDB9      ; Upload tilemap

; Set source for uploading decompressed data
C3D518:  LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         RTS

; Unpack and upload graphics and tilemaps for dense clouds
C3D522:  JSR C3D439      ; Upload font GFX
         JSR C3D6B1      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JSR C3D66B      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D543      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D66B      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D543      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for dense clouds
C3D543:  JSR C3D686      ; Set ptrs loc
         LDX #$FC1A      ; Tiles loc LBs
         LDA #$7E        ; Tiles loc HB
         JMP C3D706      ; Build map

; Add 4bpp graphics to Mode 7 map (first 128 tiles)
C3D552:  LDY $00         ; Palette index
         LDX #$9800      ; Src: 7F/9800
         JMP C3D74F      ; Convert GFX

; Add 4bpp graphics to Mode 7 map (last 128 tiles)
C3D562:  LDY #$0080      ; Palette index
         LDX #$A800      ; Src: 7F/A800
         JMP C3D74F      ; Convert GFX

; Unpack and upload graphics and tilemaps for grassfield scenes
C3D573:  JSR C3D439      ; Upload font GFX
         JSR C3D694      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         BRA C3D582      ; Upload M7 map

; Unpack and upload graphics and tilemaps for second-last airship scene
C3D57F:  JSR C3D694      ; Unpack map, GFX
C3D582:  JSR C3D664      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D59B      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D664      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D59B      ; Insert tilemap B
         JSR C3D64C      ; Upload M7 map B
         RTL

; Assemble half of grassfield tilemap
C3D59B:  JSR C3D675      ; Set ptrs loc
         LDX #$DD3A      ; Tiles loc LBs
         LDA #$7E        ; Tiles loc HB
         JMP C3D706      ; Build map

; Unpack and upload graphics and tilemaps for boat scene
C3D5AA:  JSR C3D439      ; Upload font GFX
         JSR C3D694      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JSR C3D664      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D5CB      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D664      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D5CB      ; Insert tilemap B
         BRA C3D64C      ; Upload M7 map B

; Assemble half of tilemap for sea with boat
C3D5CB:  JSR C3D67F      ; Set ptrs loc
         LDX #$2CFA      ; Tiles loc LBs
         LDA #$7F        ; Tiles loc HB
         JMP C3D706      ; Build map

; Unpack and upload graphics and tilemaps for skimming airship scene
C3D5DA:  JSR C3D439      ; Upload font GFX
         JSR C3D694      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JSR C3D664      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D5FB      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D664      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D5FB      ; Insert tilemap B
         BRA C3D64C      ; Upload M7 map B

; Assemble half of tilemap for sea without boat
C3D5FB:  JSR C3D686      ; Set ptrs loc
         LDX #$2CFA      ; Tiles loc LBs
         LDA #$7F        ; Tiles loc HB
         JMP C3D706      ; Build map

; Unpack and upload graphics and tilemaps for final airship scene
C3D60A:  JSR C3D6B1      ; Unpack map, GFX
         JSR C3D66B      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D625      ; Insert tilemap
         JSR C3D634      ; Upload M7 map A
         JSR C3D66B      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D625      ; Insert tilemap B
         BRA C3D64C      ; Upload M7 map B

; Assemble half of tilemap for final airship scene
C3D625:  JSR C3D675      ; Set ptrs loc
         LDX #$041A      ; Tiles loc LBs
         LDA #$7F        ; Tiles loc HB
         JMP C3D706      ; Build map

; Upload upper half of Mode 7 map
C3D634:  LDY #$B800      ; 7F/B800
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDX #$4000      ; Bytes: 16384
         LDY $00         ; VRAM pointer
         JMP C3DDB_      ; Upload map

; Upload lower half of Mode 7 map
C3D64C:  LDY #$B800      ; 7F/B800
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDX #$4000      ; Bytes: 16384
         LDY #$2000      ; VRAM pointer
         JMP C3DDB_      ; Upload map

; Set palette index table location for plains or sea
C3D664:  LDX #$F9E1      ; Ptrs loc LBs
         LDA #$CF        ; Ptrs loc HB
         BRA C3D670      ; Set pointer

; Set palette index table location for sky scenes
C3D66B:  LDX #$F969      ; CF/F969
         LDA #$CF        ; Bank: CF
C3D670:  STX $91         ; Set loc LBs
         STA $93         ; Set loc HB
         RTS

; Set tilemap pointer table location for final scenes
C3D675:  LDX #$FAE9      ; CF/FAE9
         LDA #$CF        ; Bank: CF
C3D67A:  STX $F7         ; Set loc LBs
         STA $F9         ; Set loc HB
         RTS

; Set tilemap pointer table location for boat scene
C3D67F:  LDX #$FAC9      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3D67A      ; Set pointer

; Set tilemap pointer table location for skimming airship and cloud scenes
C3D686:  LDX #$FAA9      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3D67A      ; Set pointer

; Set tilemap pointer table location for sideview airship scene
C3D68D:  LDX #$FB09      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3D67A      ; Set pointer

; Unpack credits scene GFX and maps, move ocean and grassfield GFX
C3D694:  JSR C3D6CE      ; Unpack data
         LDX #$141A      ; 7F/141A
         STX $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDY #$9800      ; 7F/9800
         STY $EB         ; Set dst LBs
;        LDA #$7F        ; Bank: 7F
         STA $ED         ; Set dst HB
         LDY #$18E0      ; Bytes: 6368
         BRA C3D6EE      ; Move data

; Unpack credits scene GFX and tilemaps, move cloud and BG airship GFX
C3D6B1:  JSR C3D6CE      ; Unpack data
         LDX #$ED3A      ; 7E/ED3A
         STX $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$9800      ; 7F/9800
         STY $EB         ; Set dst LBs
         LDA #$7F        ; Bank: 7F
         STA $ED         ; Set dst HB
         LDY #$0EE0      ; Bytes: 3808
         BRA C3D6EE      ; Move data

; Unpack non-font graphics for credits scenes
C3D6CE:  LDY #$568F      ; Source LBs
         LDA #$D9        ; Source HB
         JMP C3DD61      ; Unpack data

; Upload non-font sprite graphics for credits scenes
C3D6D6:  JSR C3D518      ; Src: 7E/C000
         LDX #$17BA      ; Bytes: 6074
         LDY #$6000      ; VRAM pointer
         JMP C3DDB_      ; Upload data

; Relocate decompressed data, adjust attributes if tilemap
C3D6EE:  STY $EF         ; Set data size
;        STZ $F1         ; ...
;        STZ $F2         ; ...
         REP #$20        ; 16-bit A
         LDY $00         ; Index: 0
C3D6F6:  LDA [$E7],Y     ; Unpacked data
;        CLC             ; ...
;        ADC $F1         ; ...
         STA [$EB],Y     ; Put in buffer
         INY             ; Index +1
         INY             ; Index +1
         CPY $EF         ; Past range?
         BNE C3D6F6      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Add a 128x64 tilemap to Mode 7 map
C3D706:  STX $F1         ; Set src LBs
         STA $F3         ; Set src HB
         LDY $00         ; Index: 0
C3D708:  REP #$20        ; 16-bit A
         LDA [$F7],Y     ; Src index
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$F7],Y     ; Dst index
         STA $E7         ; Memorize it
         INY             ; Index +1
         INY             ; Index +1
         SEP #$20        ; 8-bit A
         PHY             ; Save index
         TXY             ; Src index
         JSR C3D723      ; Copy 32x32 map
         PLY             ; Restore index
         CPY #$0020      ; Done 8 maps?
         BNE C3D708      ; Loop if not
         RTS

; Add a 32x32 tilemap to Mode 7 map
C3D723:  LDA #$20        ; Rows: 32
         STA $E0         ; Set counter
C3D72C:  LDA #$20        ; Columns: 32
         STA $E1         ; Set counter
         LDX $E7         ; Dst index
C3D732:  LDA [$F1],Y     ; Tile number
         STA $7FB800,X   ; Add to M7 map
         INY             ; Src index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEC $E1         ; One less column
         BNE C3D732      ; Loop till last
         INC $E8         ; Dst: +128 tiles
         DEC $E0         ; One less row
         BNE C3D72C      ; Loop till last
         RTS

; Add 4bpp tile graphics to Mode 7 map
C3D74F:  LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STX $E7         ; Set src LBs
         STY $E4         ; Set pal index
         LDA #$80        ; Tiles: 128
         STA $ED         ; Set counter
         LDX $00         ; Dst index: 0
C3D75A:  LDA #$08        ; Rows left: 8
         STA $E6         ; Set counter

; Fork: Load 8-pixel row
C3D75E:  REP #$20        ; 16-bit A
         LDY #$0010      ; Src index: 16
         LDA [$E7]       ; Planes A & B
         STA $F1         ; Memorize them
         LDA [$E7],Y     ; Planes C & D
         STA $EF         ; Memorize them
         SEP #$20        ; 8-bit A

; Fork: Convert each pixel in row
C3D76E:  LDY #$0008      ; Pixels: 8
C3D771:  TDC             ; Clear A
         ASL $F0         ; Get plane D
         ROL A           ; Roll into A
         ASL $EF         ; Get plane C
         ROL A           ; Roll into A
         ASL $F2         ; Get plane B
         ROL A           ; Roll into A
         ASL $F1         ; Get plane A
         ROL A           ; Roll into A
         AND #$0F        ; Blank pixel?
         BEQ C3D792      ; Branch if so
         STA $E0         ; Save 0-15 color
         PHY             ; Save pixels left
         LDY $E4         ; Palette index
         LDA [$91],Y     ; Palette number
         PLY             ; Pixels left
         JSR x16         ; Palette x 16
         ORA $E0         ; Add 0-15 color
C3D792:  STA $7FB801,X   ; Set map pixel
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEY             ; One less pixel
         BNE C3D771      ; Loop till last

; Fork: Do tile's next row
C3D79A:  LDY $E7         ; Source
         INY             ; Source +1
         INY             ; Source +1
         STY $E7         ; Save changes
         DEC $E6         ; One less row
         BNE C3D75E      ; Loop till last

; Fork: Do next tile
C3D7A4:  REP #$21        ; 16-bit A; C-
         INC $E4         ; Pal index +1
         LDA $E7         ; Source
         ADC #$0010      ; Skip done data
         STA $E7         ; Save changes
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         DEC $ED         ; One less tile
         BNE C3D75A      ; Loop till last
         RTS

; Handle credits timing for sideview airship scene
C3D7B9:  LDY $CF         ; Scene timer
         CPY #$003C      ; 60?
         BNE C3D816      ; Exit if not
         LDX #$9894      ; Source LBs
         JMP credx3      ; Init producer

; Handle credits timing for aerial-view airship scene
C3D7CB:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D7DC      ; Branch if not
         LDX #$98A0      ; Source LBs
         JMP credx5      ; Init director

; Fork: Main programmer
C3D7DC:  CPY #$01AE      ; 430?
         BNE C3D7E6      ; Branch if not
         LDX #$98B4      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Graphic director (page 1)
C3D7E6:  CPY #$0352      ; 850?
         BNE C3D7F0      ; Branch if not
         LDX #$98CC      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Graphic director (page 2)
C3D7F0:  CPY #$04F6      ; 1270?
         BNE C3D7FA      ; Branch if not
         LDX #$98E4      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Music
C3D7FA:  CPY #$069A      ; 1690?
         BNE C3D804      ; Branch if not
         LDX #$98FC      ; Source LBs
         JMP credx3      ; Init sprites

; Fork: Image design
C3D804:  CPY #$083E      ; 2110?
         BNE C3D80E      ; Branch if not
         LDX #$9908      ; Source LBs
         JMP credx4      ; Init sprites

; Fork: Battle planner
C3D80E:  CPY #$09E2      ; 2530?
         BNE C3D816      ; Exit if not
         LDX #$9918      ; Source LBs
         JMP credx6      ; Init sprites
C3D816:  SEC             ; Set to requeue
         RTS

; Handle credits timing for boat scene
C3D819:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D82A      ; Branch if not
         LDX #$9930      ; Source LBs
         JMP credx8      ; Init field pln

; Fork: Event planner
C3D82A:  CPY #$01AE      ; 430?
         BNE C3D834      ; Branch if not
         LDX #$9950      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Effect programmer
C3D834:  CPY #$0352      ; 850?
         BNE C3D83E      ; Branch if not
         LDX #$9968      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Battle programmer
C3D83E:  CPY #$04F6      ; 1270?
         BNE C3D816      ; Exit if not
         LDX #$9980      ; Source LBs
         JMP credx4      ; Init sprites

; Handle credits timing for skimming airship scene
C3D849:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D85A      ; Branch if not
         LDX #$9990      ; Source LBs
         JMP credx4      ; Init sound prg

; Fork: Effect graphic designer
C3D85A:  CPY #$01AE      ; 430?
         BNE C3D864      ; Branch if not
         LDX #$99A0      ; Source LBs
         JMP credx5      ; Init sprites

; Fork: Field graphic designer (page 1)
C3D864:  CPY #$0352      ; 850?
         BNE C3D86E      ; Branch if not
         LDX #$99B4      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Field graphic designer (page 2)
C3D86E:  CPY #$04F6      ; 1270?
         BNE C3D878      ; Branch if not
         LDX #$99D8      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Field graphic designer (page 3)
C3D878:  CPY #$069A      ; 1690?
         BNE C3D882      ; Branch if not
         LDX #$99FC      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Monster graphic designer
C3D882:  CPY #$083E      ; 2110?
         BNE C3D88C      ; Branch if not
         LDX #$9A20      ; Source LBs
         JMP credx5      ; Init sprites

; Fork: Object graphic designer
C3D88C:  CPY #$09E2      ; 2530?
         BNE C3D96A      ; Exit if not
         LDX #$9A34      ; Source LBs
         JMP credx5      ; Init sprites

; Handle credits timing for frontview airship scene
C3D897:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D8A8      ; Branch if not
         LDX #$9A48      ; Source LBs
         JMP credx4      ; Init sound eng

; Fork: Sound effect (page 1)
C3D8A8:  CPY #$01AE      ; 430?
         BNE C3D8B2      ; Branch if not
         LDX #$9A58      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Sound effect (page 2)
C3D8B2:  CPY #$0352      ; 850?
         BNE C3D8BC      ; Branch if not
         LDX #$9A70      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Remake planner, translator
C3D8BC:  CPY #$04F6      ; 1270?
         BNE C3D8C6      ; Branch if not
         LDX #$9A88      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: System engineer (page 1)
C3D8C6:  CPY #$069A      ; 1690?
         BNE C3D8D0      ; Branch if not
         LDX #$9AAC      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: System engineer (page 2)
C3D8D0:  CPY #$083E      ; 2110?
         BNE C3D8DA      ; Branch if not
         LDX #$9AC4      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Executive producer
C3D8DA:  CPY #$09E2      ; 2530?
         BNE C3D96A      ; Exit if not
         LDX #$9ADC      ; Source LBs
         JMP credx6      ; Init sprites
C3D96A:  SEC             ; Set to requeue
         RTS

; Handle credits timing for aerial-view plains scene
C3D8E5:  LDY $CF         ; Scene timer
         CPY #$00F0      ; 240?
         BNE C3D8F6      ; Branch if not
         LDX #$9AF4      ; Source LBs
         JMP credx10     ; Init test coord

; Fork: Special thanks (page 1)
C3D8F6:  CPY #$02D0      ; 720?
         BNE C3D900      ; Branch if not
         LDX #$9B1C      ; Source LBs
         BRA credx10     ; Init sprites

; Fork: Special thanks (page 2)
C3D900:  CPY #$04B0      ; 1200?
         BNE C3D90A      ; Branch if not
         LDX #$9B44      ; Source LBs
         BRA credx9      ; Init sprites

; Fork: Special thanks (page 3)
C3D90A:  CPY #$0690      ; 1680?
         BNE C3D914      ; Branch if not
         LDX #$9B68      ; Source LBs
         BRA credx8      ; Init sprites

; Fork: Special thanks (page 4)
C3D914:  CPY #$0870      ; 2160?
         BNE C3D91E      ; Branch if not
         LDX #$9B88      ; Source LBs
         BRA credx6      ; Init sprites

; Fork: Special thanks (page 5)
C3D91E:  CPY #$0A50      ; 2640?
         BNE C3D928      ; Branch if not
         LDX #$9BA0      ; Source LBs
         BRA credx5      ; Init sprites

; Fork: Special thanks (page 6)
C3D928:  CPY #$0C30      ; 3120?
         BNE C3D96A      ; Exit if not
         LDX #$9BB4      ; Source LBs
         BRA credx9      ; Init sprites

; Handle credits timing for rearview airship scene
C3D933:  LDY $CF         ; Scene timer
         CPY #$003C      ; 60?
         BNE C3D944      ; Branch if not
         LDX #$9BD8      ; Source LBs
         BRA credx6      ; Init thanks_p7

; Fork: Special thanks (page 8)
C3D944:  CPY #$01E0      ; 480?
         BNE C3D94E      ; Branch if not
         LDX #$9BF0      ; Source LBs
         BRA credx6      ; Init sprites

; Fork: Special thanks (page 9)
C3D94E:  CPY #$0384      ; 900?
         BNE C3D958      ; Branch if not
         LDX #$9C08      ; Source LBs
         BRA credx5      ; Init sprites

; Fork: Special thanks (page 10)
C3D958:  CPY #$0528      ; 1320?
         BNE C3D962      ; Branch if not
         LDX #$9C1C      ; Source LBs
         BRA credx5      ; Init sprites

; Fork: Special thanks (page 11)
C3D962:  CPY #$06CC      ; 1740?
         BNE C3D96A      ; Exit if not
         LDX #$9C30      ; Source LBs
         BRA credx5      ; Init sprites

; Initialize credits (3 sprites)
credx3:  LDA #$03        ; Sprites: 3
         BRA C3DBA5      ; Init sprites

; Initialize credits (4 sprites)
credx4:  LDA #$04        ; Sprites: 4
         BRA C3DBA5      ; Init sprites

; Initialize credits (5 sprites)
credx5:  LDA #$05        ; Sprites: 5
         BRA C3DBA5      ; Init sprites

; Initialize credits (6 sprites)
credx6:  LDA #$06        ; Sprites: 6
         BRA C3DBA5      ; Init sprites

; Initialize credits (8 sprites)
credx8:  LDA #$08        ; Sprites: 8
         BRA C3DBA5      ; Init sprites

; Initialize credits (9 sprites)
credx9:  LDA #$09        ; Sprites: 9
         BRA C3DBA5      ; Init sprites

; Initialize credits (10 sprites)
credx10: LDA #$0A        ; Sprites: 10

; Initialize sprites for current credits strings
C3DBA5:  STA $FA         ; String count
         STX $F7         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $F9         ; Set src HB
         LDY $00         ; Index: 0
C3DBAD:  REP #$20        ; 16-bit A
         LDA [$F7],Y     ; Anim table ptr
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$F7],Y     ; Position
         STA $60         ; Memorize it
         SEP #$20        ; 8-bit A
         PHY             ; Save index
         TXY             ; Anim table ptr
         JSR C3DC14      ; Init sprite
         PLY             ; Table index
         INY             ; Index +1
         INY             ; Index +1
         DEC $FA         ; One less string
         BNE C3DBAD      ; Loop till last
         SEC             ; Set to requeue
         RTS

; Build credits' OAM table for sideview airship scene
C3D96D:  LDX #$9DC0      ; Source LBs
         LDA #$01        ; Sprites: 1
         JSR C3DBC8      ; Do position
         LDX #$9C44      ; Source LBs
         LDA #$02        ; Sprites: 2
         BRA C3DBE8      ; Do staff

; Build credits' OAM table for aerial-view airship scene
C3D983:  LDX #$9DC4      ; Source LBs
         LDA #$0A        ; Sprites: 10
         JSR C3DBC8      ; Do positions
         LDX #$9C4C      ; Source LBs
         LDA #$18        ; Sprites: 24
         BRA C3DBE8      ; Do staff

; Build credits' OAM table for boat scene
C3D999:  LDX #$9DEC      ; Source LBs
         LDA #$06        ; Sprites: 6
         JSR C3DBC8      ; Do positions
         LDX #$9CAC      ; Source LBs
         LDA #$10        ; Sprites: 16
         BRA C3DBE8      ; Do staff

; Build credits' OAM table for skimming airship scene
C3D9AF:  LDX #$9E04      ; Source LBs
         LDA #$08        ; Sprites: 8
         JSR C3DBC8      ; Do positions
         LDX #$9CEC      ; Source LBs
         LDA #$19        ; Sprites: 25
         BRA C3DBE8      ; Do staff

; Build credits' OAM table for frontview airship scene
C3D9C5:  LDX #$9E24      ; Source LBs
         LDA #$09        ; Sprites: 9
         JSR C3DBC8      ; Do positions
         LDX #$9D50      ; Source LBs
         LDA #$1C        ; Sprites: 28
         BRA C3DBE8      ; Do staff

; Build credits' OAM table for aerial-view plains scene
C3D9DB:  LDX #$9E48      ; Source LBs
         LDA #$39        ; Sprites: 57
         BRA C3DBC8      ; Build OAM

; Build credits' OAM table for rearview airship scene
C3D9E6:  LDX #$9F2C      ; Source LBs
         LDA #$1B        ; Sprites: 27

; Build OAM table for scene's small credits strings
C3DBC8:  JSR credini     ; Set src, index
C3DBCA:  LDX #$0B00      ; Adr MSB, pal 5
         JSR credptr     ; Init data
         CLC             ; Letter: 8x8
         JSR C3DD02      ; Build table
         LDY $FE         ; Pointer index
         DEC $4D         ; One less sprite
         BNE C3DBCA      ; Loop till last
         RTS

; Build OAM table for scene's large credits strings
C3DBE8:  JSR credini     ; Set src, index
C3DBEA:  LDX #$0900      ; Adr MSB, pal 4
         JSR credptr     ; Init data
         SEC             ; Letter: 16x16
         JSR C3DD02      ; Build table
         LDY $FE         ; Pointer index
         DEC $4D         ; One less sprite
         BNE C3DBEA      ; Loop till last
         RTS

; Set pointer to OAM table for scene's credits strings
credini: STA $4D         ; String count
         STX $4A         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $4C         ; Set src HB
         LDY $00         ; Index: 0
         RTS

; Load pointers for credit string, etc.
credptr: STX $F1         ; Save attribs
         REP #$20        ; 16-bit A
         LDA [$4A],Y     ; Source LBs
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$4A],Y     ; Dest LBs
         INY             ; Index +1
         INY             ; Index +1
         STY $FE         ; Save index
         TAY             ; Dest LBs
         SEP #$20        ; 8-bit A
         JSR C3DD31      ; Set OAM tbl ptr
         LDY $00         ; Index: 0
         STA [$EB],Y     ; Set size
         INY             ; Index +1
         STZ $E0         ; Rel X: 0
;        STZ $EF         ; No use...
;        STZ $F0         ; No use...
         RTS

; Initialize sprite for current credit string
C3DC14:  STY $F1         ; Save anim ptr
         STZ $AF         ; Request fade-in
         LDY #C3DC44     ; C3/DC44
         JSR qanim0      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$01A4      ; Frames: 420
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
         PEI ($60)       ; Coordinates
         PEI ($F1)       ; Anim ptr LBs
         LDA #$7E        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3E9DX      ; Set sprite's

; Animate credit string
C3DC44:  BNE C3DC84      ; If mode 1

; Mode 0: Initialize sprite
C3DC4C:  INC $3649,X     ; Mode +1
         LDA $344A,X     ; Sprite's Y
         CLC             ; Prepare ADC
         ADC #$20        ; Go 32 px down
         STA $344A,X     ; Save changes
         REP #$20        ; 16-bit A
         LDA #$FF80      ; V-Spd: -0.5 px
         STA $3549,X     ; Set sprite's
         STZ $34C9,X     ; H-Speed: 0
         JSR C31206      ; Set pose timer
         LDA $AF         ; Handled fade-in?
         BNE C3DC84      ; Skip it if so
         PHB             ; Save DB
         LDA $B4         ; Text on clouds?
         BNE C3DC7C      ; Use blue if so
         JSR C3C703      ; Fade-in: White
         BRA C3DC7F      ; Skip a line
C3DC7C:  JSR C3C72A      ; Fade-in: Blue
C3DC7F:  LDA #$01        ; Mark as handled
         STA $AF         ; Allow fade-out
         PLB             ; Restore DB

; Mode 1: Sustain sprite
C3DC84:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BEQ C3DCA9      ; Delete if so
         CPY #$0164      ; 356?
         BNE C3DC96      ; Scroll if not
         STZ $3549,X     ; V-Speed LB: 0
         STZ $354A,X     ; V-Speed HB: 0
C3DC96:  CPY #$0080      ; 128?
         BEQ C3DCAB      ; Fade if so
C3DC9B:  JSR C3DEC0      ; Scroll & OAM
         JSR C3CFE5      ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3DCA9:  CLC             ; Set to dequeue
         RTS

; Fork: Set to fade all text
C3DCAB:  LDA $AF         ; Already set?
         BEQ C3DC9B      ; Skip if so
         STZ $AF         ; Mark as handled
         PHB             ; Save DB
         JSR C3C6DC      ; Trigger fade
         PLB             ; Restore DB
         BRA C3DC9B      ; Scroll & OAM

; Build OAM for credit letter
C3DD02:  LDA [$E7]       ; At terminator?
         BEQ C3DCA9      ; Exit if so
         PHP             ; Save size flag
         PHA             ; Save letter
         TDC             ; Clear A
         ROR A           ; #$80 if 16x16
         ORA $E0         ; Add relative X
         STA [$EB],Y     ; Set for letter
         INY             ; Index +1
         TDC             ; Relative Y: 0
         STA [$EB],Y     ; Set letter's
         INY             ; Index +1
         PLA             ; Letter
         REP #$21        ; 16-bit A; C-
         ADC $F1         ; Add attribs
         STA [$EB],Y     ; Set attribs
         INC $E7         ; Letter +1
         INY             ; Index +1
         INY             ; Index +1
         SEP #$21        ; 8-bit A; C+
         LDA $E0         ; Relative X
         ADC #$07        ; Go 8 px right
         STA $E0         ; Save changes
         PLP             ; Tile size flag
         BRA C3DD02      ; Do next letter

; Set OAM table pointer for credit string, compute string size
C3DD31:  STX $E7         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $E9         ; Set src HB
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         REP #$21        ; 16-bit A; C-
         LDA $EB         ; Dest LBs
         ADC #$0003      ; +3 bytes
         STA [$EB]       ; Set OAM ptr
         INC $EB         ; Dst LBs +1
         INC $EB         ; Dst LBs +1
         SEP #$20        ; 8-bit A
         LDA #$FE        ; Time: Infinite
         STA [$EB]       ; Set pose timer
         INC $EB         ; Dst LBs +1
         LDY $00         ; Letter: 1st
C3DD55:  LDA [$E7],Y     ; Letter
         BEQ C3DD5F      ; If terminator
         INY             ; Index +1
         BRA C3DD55      ; Do next letter
C3DD5F:  TYA             ; String size
         RTS

; Decompress data
C3DD61:  STY $F3         ; Set src LBs
         STA $F5         ; Set src HB
         LDY #$C000      ; 7E/C000
         STY $F6         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $F8         ; Set dst HB
         JSL $C2FF6D     ; Unpack data
         RTS

; Clear VRAM
C3DD73:  REP #$20        ; 16-bit A
         STZ $2116       ; VRAM: $0000
         LDA #$8000      ; Loop counter
         JMP C3B113      ; Clear VRAM

; Convert and upload graphics for range of font characters
C3DD86:  STY $2116       ; Set VRAM ptr
         STX $EB         ; Set data size
         STA $E9         ; Set src HB
         LDY $00         ; Index: 0
         REP #$20        ; 16-bit A
C3DD8D:  LDX #$0008      ; 8-px rows: 8
C3DD90:  LDA [$E7],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         DEX             ; One less row
         BNE C3DD90      ; Loop till last
         LDX #$0008      ; 8-px rows: 8
.loop    STZ $2118       ; Planes C and D
         DEX             ; One less row
         BNE .loop       ; Loop till last
         CPY $EB         ; More tiles?
         BNE C3DD8D      ; Loop if so
         SEP #$20        ; 8-bit A
         RTS

; Upload data manually, adjust attributes if tilemap
C3DDB_:  STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
C3DDB9:  REP #$20        ; 16-bit A
         STY $2116       ; Set VRAM ptr
         STX $EB         ; Set data size
         LDY $00         ; Index: 0
C3DDC1:  LDA [$E7],Y     ; Source data
         CLC             ; Prepare ADC
         ADC $ED         ; Add attribs
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY $EB         ; Past range?
         BNE C3DDC1      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Build Mode 7 matrix tables for HDMA
C3DDD2:  PHB             ; Save DB
         TDC             ; Bank: 00
         PHA             ; Put on stack
         PLB             ; Set DB to 0

; Fork: Define scale dividend
C3DDD9:  LDA $C3         ; Dividend index
         JSR C3DE76      ; Signed dividend
;        STA $E0         ; ...
         STA $EB         ; Memorize it
;        LDA $E0         ; Positive?
         BPL C3DDEA      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3DDEA:  LSR A           ; Halve it
         STA $CB         ; Save dividend

; Fork: Define shear dividend
C3DDEF:  LDA $C3         ; Dividend index
         JSR C3DE7A      ; Signed dividend
;        STA $E0         ; ...
         STA $ED         ; Memorize it
;        LDA $E0         ; Positive?
         BPL C3DE00      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3DE00:  LSR A           ; Halve it
         STA $C9         ; Save dividend

; Fork: Define matrices A and D for two scanlines
C3DE05:  LDY #$01BE      ; Scanline: Last
         LDA $C5         ; Base divisor
         STA $E7         ; Memorize it
C3DE0C:  LDA $CB         ; Scale dividend
         STA $4204       ; To register
         SEP #$20        ; 8-bit A
         LDA $E8         ; Map factor HB
         STA $4206       ; Set divisor
         JSR x32r        ; 16-bit A; cycles
         LDA $EB         ; Positive mod?
         BPL C3DE2C      ; Branch if so
         LDA $4214       ; Quotient
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3DE2F      ; Skip a line
C3DE2C:  LDA $4214       ; Quotient
C3DE2F:  STA $0602,Y     ; Set line 1
         STA $0604,Y     ; Set line 2

; Fork: Define matrices B and C for two scanlines
C3DE35:  LDA $C9         ; Shear dividend
         STA $4204       ; To register
         SEP #$20        ; 8-bit A
         LDA $E8         ; Map factor HB
         STA $4206       ; Set divisor
         JSR x32r        ; 16-bit A; cycles
         LDA $E7         ; Matrix divisor
         SEC             ; Prepare SBC
         SBC $C7         ; Deduct "angle"
         STA $E7         ; Save changes
         LDA $ED         ; Positive mod?
         BPL C3DE59      ; Branch if so
         LDA $4214       ; Quotient
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         BRA C3DE5C      ; Skip a line
C3DE59:  LDA $4214       ; Quotient
C3DE5C:  STA $07C4,Y     ; Set line B1
         STA $07C6,Y     ; Set line B2
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         STA $0986,Y     ; Set line C1
         STA $0988,Y     ; Set line C2
         DEY             ; Index -1
         DEY             ; Index -1
         DEY             ; Index -1
         DEY             ; Index -1
         BPL C3DE0C      ; Loop if > 0
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Load animation modifier
C3DE76:  REP #$21        ; 16-bit A; C-
         ADC #$0040      ; Index +64
C3DE7A:  AND #$00FF      ; Clear HB
         ASL A           ; Double it
         TAX             ; Index it
         LDA $C2FC6D,X   ; Modifier
         RTS

; Animate linearly moving temporary sprite
C3DE84:  BNE C3DE94      ; If mode 1

; Mode 0: Initialize timer
C3DE8C:  JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain sprite
C3DE94:  LDY $3349,X     ; Timer expired?
         BEQ C3DEA9      ; Delete if so
         JSR C3DEC0      ; Scroll & OAM
         JSR C3CFE5      ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3DEA9:  CLC             ; Set to dequeue
         RTS

; Animate regular permanent sprite
C3DEAB:  BNE C3DEBB      ; If mode 1

; Mode 0: Initialize timer
C3DEB3:  JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain sprite
C3DEBB:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Scroll sprite and define OAM
C3DEC0:  LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $33C9,X     ; Fractional X
         ADC $34C9,X     ; Add H-Speed
         STA $33C9,X     ; Save changes
         LDA $3449,X     ; Fractional Y
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add V-Speed
         STA $3449,X     ; Save changes
         JMP C31221      ; Define OAM

; Animate true actor name or "And you"
C3DEDD:  STA $E0         ; Save mode
         LDA $47         ; At 2nd actor?
         BNE C3DEE9      ; Delete if so
         LDA $E0         ; Anim mode
         TAX             ; Index it
         JMP (C3DEEB,X)  ; Handle mode
C3DEE9:  CLC             ; Set to dequeue
         RTS

; Jump table for the above
C3DEEB:  dw C3DEFF       ; Initialize sprite
         dw C3DF13       ; Refresh sprite
         dw C3DF1B       ; Set to scroll up
         dw C3DF13       ; Refresh sprite
         dw C3DF23       ; Stop scrolling
         dw C3DF13       ; Refresh sprite
         dw C3DF2A       ; Set to scroll up
         dw C3DF13       ; Refresh sprite
         dw C3DEFD       ; Delete sprite

; Mode 8: Delete sprite
C3DEFD:  CLC             ; Set to dequeue
         RTS

; Mode 0: Initialize sprite
C3DEFF:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         STZ $3549,X     ; V-Speed: 0
         LDA $85         ; Scroll delay
         STA $3349,X     ; Set mode timer
         JSR C31206      ; Set pose timer

; Modes 1, 3, 5: Refresh sprite
C3DF13:  JSR C3DF4B      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 2: Set to scroll upward 2.5s
C3DF1B:  LDY #$FFC0      ; V-Spd: -0.25 px
         LDX #$0096      ; Frames: 150
         BRA C3DF32      ; Set spd, timer

; Mode 4: Stop scrolling
C3DF23:  LDY $00         ; V-Speed: 0
         LDX #$00F0      ; Frames: 240
         BRA C3DF32      ; Set spd, timer

; Mode 6: Set to scroll upward 5s
C3DF2A:  LDY #$FFC0      ; V-Spd: -0.25 px
         LDX #$012C      ; Frames: 300

; Fork: Change V-Speed and mode timer
C3DF32:  PHX             ; Save timer
         LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         TYA             ; V-Speed
         STA $3549,X     ; Set sprite's
         PLA             ; Mode timer
         STA $3349,X     ; Set sprite's
         BRA C3DF13      ; Scroll & OAM

; Decrease animation timer, advance mode if expired
C3DF4B:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDY $3349,X     ; Timer expired?
         BNE C3DF59      ; Branch if not
         INC $3649,X     ; Mode +1
         BRA C3DF5C      ; Skip a line
C3DF59:  DEC $3349,X     ; Timer -1
C3DF5C:  SEP #$20        ; 8-bit A
         RTS

; Draw, center, and set to upload actor's pseudonym
C3DF5F:  LDY $00         ; 1st: Terra
C3DF61:  STY $EB         ; Save slot
         REP #$20        ; 16-bit A
         TYA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor in slot
         CMP $28         ; Matches ours?
         BEQ C3DF99      ; Proceed if so
         LDY $EB         ; Actor slot
         INY             ; Actor slot +1
         CPY #$0010      ; Done all 16?
         BNE C3DF61      ; Loop if not

; Fork: Default to "??????" (Gogo, Umaro)
C3DF89:  LDX $00         ; Dst index: 0
         LDA.B #!ques    ; Char: "?"
C3DF8D:  STA $7E9E89,X   ; Add to string
         INX             ; Index +1
         CPX #$0006      ; Done 6 chars?
         BNE C3DF8D      ; Loop if not
         BRA C3DFA9      ; Skip alt case

; Fork: Load actor's name
C3DF99:  LDX $00         ; Dst index: 0
C3DF9B:  LDA $0002,Y     ; Letter
         STA $7E9E89,X   ; Add to string
         INY             ; Src index +1
         INX             ; Dst index +1
         CPX #$0006      ; Done 6 chars?
         BNE C3DF9B      ; Loop if not
C3DFA9:  JSR C3DFB3      ; Center name
         JSR C3A611      ; Build tilemap
         JMP C3A63B      ; Load graphics

; Center BG3 camera on actor's pseudonym
C3DFB3:  LDX $00         ; Letter: 1st
         STX $E0         ; Width: 0
C3DFB9:  TDC             ; Clear A
         LDA $7E9E89,X   ; Letter
         CMP #$FF        ; Terminator?
         BEQ C3DFD7      ; Branch if so
         PHX             ; Save index
         SEC             ; Prepare SBC
         SBC #$60        ; Use field format
         TAX             ; Index it
         LDA $C48FC0,X   ; Letter width
         CLC             ; Prepare ADC
         ADC $E0         ; Add to total
         STA $E0         ; Save total
         PLX             ; Letter index
         INX             ; Point to next
         CPX #$0006      ; Done all 6?
         BNE C3DFB9      ; Loop if not
C3DFD7:  REP #$20        ; 16-bit A
         LSR $E0         ; Halve text width
         LDA #$0080      ; BG3's width / 2
         SEC             ; Prepare SBC
         SBC $E0         ; Subtract text's
         EOR #$FFFF      ; Invert value
         INC A           ; Add one
         STA $3D         ; Set BG3 X-Pos
         SEP #$20        ; 8-bit A
         RTS

; Temporarily scroll BG1 westward
C3E002:  REP #$20        ; 16-bit A
         LDA $3349,X     ; Timer expired?
         BEQ C3E01E      ; Dequeue if so
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3E01C      ; Pause if > 0
         REP #$20        ; 16-bit A
         INC $35         ; BG1 X-Pos +1
C3E01C:  SEC             ; Set to requeue
         RTS             ; Exit
C3E01E:  CLC             ; Set to dequeue
         RTS

; Create actor's first and last names
C3E022:  LDA $28         ; Actor
         XBA             ; Put it in B
         LDA #$06        ; Name data size
         JSR mul8        ; Actor x size
         TAX             ; Index product
         REP #$20        ; 16-bit A
         LDA $C28DE4,X   ; Anim ptr A
         TAY             ; Put in Y
         LDA $C28DE7,X   ; Anim ptr B
         PHA             ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $C28DE6,X   ; Name A's X
         PHA             ; Memorize it
         LDA $C28DE9,X   ; Name B's X
         STA $54         ; Memorize it
         LDA #$C2        ; Anim ptr HB
         JSR C3E08F      ; Create name A
         PLA             ; X position
         STA $7E33CA,X   ; Set name A's
         LDA #$C2        ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JSR C3E08F      ; Create name B
         LDA $54         ; X position
         STA $7E33CA,X   ; Set name B's
         RTS

; Create true actor name or "And you"
C3E08F:  PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3DEDD     ; C3/DEDD
         JSR qanim1      ; Queue anim fn
         LDA #$D0        ; Y: 208
         STA $7E344A,X   ; Set sprite's
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JMP anm_st      ; Set sprite's

; Create "And you"
C3E098:  LDA #$CF        ; Anim ptr HB
         LDY #$F8AB      ; Anim ptr LBs
         JSR C3E08F      ; Create sprite
         LDA #$68        ; X: 104
         STA $7E33CA,X   ; Set sprite's
         RTS

; Initialize font, BG, and register data for actor scene
C3E0B9:  STA $28         ; Set actor slot
         JSL $D4CE8C     ; Init registers
         JSR C36A3C      ; Clear BG3 A
         JSR C36A28      ; Clear BG2 A
         LDY #$3049      ; To BG pal 0
         JSR black       ; BGP0: Black
         LDY #$3069      ; To BG pal 1
         JSR black       ; BGP1: Black
         LDY #$3089      ; To BG pal 2
         JSR black       ; BGP2: Black
         LDY #$30E9      ; To BG pal 5
         JSR black       ; BGP5: Black
         LDY #$3109      ; To BG pal 6
         JSR black       ; BGP6: Black
         LDY #$3149      ; To OBJ pal 0
         JSR black       ; OBP0: Black
         LDY #$3169      ; To OBJ pal 1
         JSR black       ; OBP1: Black
         LDY #$31C9      ; To OBJ pal 4
         JSR black       ; OBP4: Black
         JSR C3EE74      ; Load big font
         JMP C3EE90      ; And BG GFX/map

; Create and upload text for actor scene, unblank screen
C3E123:  STZ $47         ; Erase name: N
         JSR C3E897      ; Create "as"
;        LDA #$2C        ; Palette 3
;        STA $29         ; No use...
         JSR C3DF5F      ; Create alias
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         JSR C314AC      ; Upload alias
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C3E022      ; Create true name
C3E13D:  JSR C3EF21      ; Queue BG1+BG3a
         INC $26         ; Scene mode +1
         JMP C3C675      ; Set brightness

; Set to fade BG elements for actor scene (also final airship's)
C3E145:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDY #$30E9      ; To BG pal 5
         LDX #C310F4     ; Black palette
         JSR slow4       ; Do tabletop
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3109      ; To BG pal 6
         LDX #C310F4     ; Black palette
         JSR slow4       ; Do overlay
C3E16B:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDY #$3069      ; To BG pal 1
         LDX #C310F4     ; Black palette
         JSR slow4       ; Do book, etc.
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3089      ; To BG pal 2
         LDX #C310F4     ; Black palette
         JMP slow4       ; Do bones, etc.

; Set to fade in BG elements for actor scene
C3E192:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3069      ; To BG pal 1
         LDX #$967C      ; C2/967C
         JSR slow2       ; Do book, etc.
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$3089      ; To BG pal 2
         LDX #$969C      ; C2/969C
         JSR slow2       ; Do bones, etc.
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$30E9      ; To BG pal 5
         LDX #$96DC      ; C2/96DC
         JSR slow2       ; Do tabletop
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$3109      ; To BG pal 6
         LDX #$96FC      ; C2/96FC
         JMP slow2       ; Do overlay

; Set to fade in actor's pseudonym and "as"
C3E1DF:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3049      ; To BG pal 0
         LDX #$9754      ; C2/9754
         JSR slow4       ; Handle name
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$3169      ; To OBJ pal 1
         LDX #$9754      ; C2/9754
         JMP slow4       ; Handle "as"

; Set to scroll and fade actor alias, fade "as", fade in true name
C3E206:  STZ $CF         ; Scroll timer LB
         STZ $D0         ; Scroll timer HB
         LDY #$00F0      ; Frames: 240
         STY $64         ; Set scroll limit
         LDY #C3D1B6     ; C3/D1B6
         JSR qanim0      ; Queue scroll fn
         JSR C3E241      ; Fade pseudonym
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3169      ; To OBJ pal 1
         LDX #C310F4     ; Black palette
         JSR slow4       ; Fade "as"
C3E22D:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3149      ; To OBJ pal 0
         LDX #$9754      ; C2/9754
         JMP slow4       ; Fade in true name

; Set to fade background palette 0
C3E241:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDY #$3049      ; To BG pal 0
         LDX #C310F4     ; Black palette
         JMP slow4       ; Queue fade-out

; Set to fade sprite palette 0
C3E255:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDY #$3149      ; To OBJ pal 0
         LDX #C310F4     ; Black palette
         JMP slow4       ; Queue fade-out

; 28: Start Shadow's scene
C3E26E:  LDA #$03        ; Actor: Shadow
         JSR C3E0B9      ; Init BGs/font
         JSR C3EF48      ; Upload apple
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in apple
         JSR C3E83F      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JSR C3E9B3      ; Create apple
         JMP C3E123      ; Create text

; Set to fade in non-glint sprites on table
C3E28A:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$9774      ; C2/9774
         JMP slow2       ; Queue fade-in

; Set to fade sprite palette 4
C3E29E:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #C310F4     ; Black palette
         JMP slow4       ; Queue fade-out

; 29: Fade in "Shadow as"
C3E2B2:  LDY $20         ; Delay expired?
         BNE C3E2C0      ; Exit if not
         INC $26         ; Next: C3/E2C1
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E2C0:  RTS

; 2A: Switch Shadow's names
C3E2C1:  LDY $20         ; Delay expired?
         BNE C3E2CF      ; Exit if not
         INC $26         ; Next: C3/E2D0
         JSR C3E206      ; Switch names
         LDY #$0168      ; Fade/Pan delay
         STY $20         ; Set for below
C3E2CF:  RTS

; 2B: Fade all but Shadow's name
C3E2D0:  LDY $20         ; Delay expired?
         BNE C3E2CF      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade apple
         JMP C3E845      ; Scroll table

; 38: Fade actor's true name
C3E2E7:  LDY $20         ; Delay expired?
         BNE C3E2CF      ; Exit if not
         LDA #$78        ; Frames: 120
         STA $20         ; Set exit delay
         LDA #$01        ; C3/C5D4
         STA $26         ; Next: Exit
         JMP C3E255      ; Queue fade-out

; 32: Start Cyan's scene
C3E2F8:  LDA #$02        ; Actor: Cyan
         JSR C3E0B9      ; Init BGs/font
         JSR C3EF68      ; Draw sword; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E468      ; Fade in glint
         LDY #$FFB8      ; X: -72 = 440
         STY $35         ; Set BG1 X-Pos
         JSR C3E839      ; Scroll table
         LDY #C3ECAE     ; C3/ECAE
         JSR qanim0      ; Queue glints
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3E123      ; Create text

; 33: Fade in "Cyan as"
C3E319:  LDY $20         ; Delay expired?
         BNE C3E327      ; Exit if not
         INC $26         ; Next: C3/E328
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E327:  RTS

; 34: Switch Cyan's names
C3E328:  LDY $20         ; Delay expired?
         BNE C3E336      ; Exit if not
         INC $26         ; Next: C3/E337
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E336:  RTS

; 35: Fade all but Cyan's name
C3E337:  LDY $20         ; Delay expired?
         BNE C3E336      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JMP C3E29E      ; Fade glint

; 40: Start Edgar and Sabin's scene
C3E34B:  LDA #$04        ; Actor: Edgar
         JSR C3E0B9      ; Init BGs/font
         JSR C3EF7E      ; Upload coin
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in coin
         LDY #C3ED39     ; C3/ED39
         JSR qanim2      ; Queue coin fn
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 41: Fade in "Edgar as"
C3E364:  LDY $20         ; Delay expired?
         BNE C3E372      ; Exit if not
         INC $26         ; Next: C3/E373
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for alias
C3E372:  RTS

; 42: Switch Edgar's names
C3E373:  LDY $20         ; Delay expired?
         BNE C3E381      ; Exit if not
         INC $26         ; Next: C3/E382
         JSR C3E206      ; Switch names
         LDA #$F0        ; Intro delay
         STA $20         ; Set for Sabin
C3E381:  RTS

; 43: Show Sabin's name, fade Edgar's
C3E382:  LDY $20         ; Delay expired?
         BNE C3E3A1      ; Exit if not
         STY $3F         ; BG3 Y-Pos: 0
         LDA #$05        ; Actor: Sabin
         STA $28         ; Set actor slot
         JSR C3E897      ; Create "as"
         JSR C3E255      ; Fade Edgar
         JSR C3DF5F      ; Create Sabin
         JSR C3E1DF      ; Fade in Sabin
         INC $26         ; Next: C3/E3A2
         LDA #$78        ; Removal delay
         STA $20         ; Set for Edgar
C3E3A1:  RTS

; 44: Delete Edgar's name
C3E3A2:  LDY $20         ; Delay expired?
         BNE C3E3B1      ; Exit if not
         INC $47         ; Erase name: Y
         INC $26         ; Next: C3/E3B2
         LDA #$B4        ; Switch delay
         STA $20         ; Set for Sabin
C3E3B1:  RTS

; 45: Switch Sabin's names
C3E3B2:  LDY $20         ; Delay expired?
         BNE C3E3B1      ; Exit if not
         LDA #$4F        ; C3/E3CD
         STA $26         ; Next: Fade BG
         LDA #$B4        ; Frames: 180
         STA $20         ; Set fade delay
         STZ $47         ; Erase name: N
         LDY #$0014      ; Frames: 20
         STY $85         ; Set scroll delay
         JSR C3E022      ; Create true name
         JMP C3E206      ; Switch names

; 4F: Fade all but Sabin's name
C3E3CD:  LDY $20         ; Delay expired?
         BNE C3E3B1      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JMP C3E29E      ; Fade coin

; 3C: Start Mog's scene
C3E3E1:  LDA #$0A        ; Actor: Mog
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFA2      ; Draw tree; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in sprites
         JSR C3E83F      ; Scroll table
         JSR C3EA24      ; Create sprites
         LDA #$78        ; Fade-in delay
         STA $20         ; Set for name
         JMP C3E123      ; Create text

; 3D: Fade in "Mog as"
C3E3FD:  LDY $20         ; Delay expired?
         BNE C3E40B      ; Exit if not
         INC $26         ; Next: C3/E40C
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E40B:  RTS

; 3E: Switch Mog's names
C3E40C:  LDY $20         ; Delay expired?
         BNE C3E41A      ; Exit if not
         INC $26         ; Next: C3/E41B
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E41A:  RTS

; 3F: Fade all but Mog's name
C3E41B:  LDY $20         ; Delay expired?
         BNE C3E41A      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade sprites
         JMP C3E845      ; Scroll table

; 46: Start Gogo's scene
C3E432:  LDA #$0C        ; Actor: Gogo
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFB8      ; Draw helmet; eye
         JSR C3E192      ; Fade in BGs
         JSR C3E839      ; Scroll table
         JSR C3E9E4      ; Create pink eye
         LDY #C3E49F     ; C3/E49F
         JSR qanim2      ; Queue eye fn
         LDA #$B4        ; Frames: 180
         STA $7E3349,X   ; Set eye delay
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 47: Fade in "Gogo as"
C3E459:  LDY $20         ; Delay expired?
         BNE C3E467      ; Exit if not
         INC $26         ; Next: C3/E47C
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for nameS
C3E467:  RTS

; Set to fade in glint on table object
C3E468:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         LDX #$955C      ; C2/955C
         JMP C30FAA      ; Queue fade-in

; 48: Switch Gogo's names
C3E47C:  LDY $20         ; Delay expired?
         BNE C3E48A      ; Exit if not
         INC $26         ; Next: C3/E48B
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E48A:  RTS

; 49: Fade all but Gogo's name
C3E48B:  LDY $20         ; Delay expired?
         BNE C3E48A      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JMP C3E29E      ; Fade eye

; Animate eye in Gogo's helmet
C3E49F:  CMP #$02        ; Mode 1?
         BEQ C3E4BA      ; Branch if so
         CMP #$06        ; Mode 3?
         BEQ C3E4DF      ; Branch if so

; Modes 0 and 2: Wait
C3E4AB:  LDA $3349,X     ; Timer expired?
         BNE C3E4B5      ; Branch if not
         INC $3649,X     ; Mode +1
C3E4B5:  DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS

; Mode 1: Fade in eye
C3E4BA:  PHB             ; Save DB
         LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         LDX #$957C      ; C2/957C
         JSR C30FAA      ; Queue fade-in
         PLB             ; Restore DB
         LDX $2D         ; Queue index
         LDA #$3C        ; Delay: 60
         STA $3349,X     ; Set fade-out's
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 3: Fade out eye
C3E4DF:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         LDX #C310F4     ; Black palette
         JSR C30FAA      ; Queue fade
         CLC             ; Set to dequeue
         RTS

; 50: Start Gau's scene
C3E4FA:  LDA #$0B        ; Actor: Gau
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFCE      ; Draw helmet; face
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in face
         JSR C3E83F      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 51: Fade in "Gau as"
C3E513:  LDY $20         ; Delay expired?
         BNE C3E533      ; Exit if not
         INC $26         ; Next: C3/E522
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
         JMP C3E1DF      ; Queue fade-in

; 52: Switch Gau's names; create face
C3E522:  LDY $20         ; Delay expired?
         BNE C3E533      ; Exit if not
         INC $26         ; Next: C3/E534
         JSR C3E994      ; Create face
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E533:  RTS

; 53: Fade all but Gau's name
C3E534:  LDY $20         ; Delay expired?
         BNE C3E533      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade face
         JMP C3E845      ; Scroll table

; 5A: Start Terra's scene
C3E54B:  TDC             ; Actor: Terra
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFE4      ; Draw glass; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E468      ; Fade in glint
         JSR C3E83F      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 5B: Fade in "Terra as"
C3E564:  LDY $20         ; Delay expired?
         BNE C3E584      ; Exit if not
         INC $26         ; Next: C3/E573
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
         JMP C3E1DF      ; Queue fade-in

; 5C: Switch Terra's names, create glint
C3E573:  LDY $20         ; Delay expired?
         BNE C3E584      ; Exit if not
         INC $26         ; Next: C3/E585
         JSR C3EA03      ; Create glint
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E584:  RTS

; 5D: Fade all but Terra's name
C3E585:  LDY $20         ; Delay expired?
         BNE C3E584      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade glint
         JMP C3E845      ; Scroll table

; 64: Start Locke and Celes's scene
C3E59C:  LDA #$01        ; Actor: Locke
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFFA      ; Draw bouquet
         JSR C3E192      ; Fade in BGs
         JSR C3E83F      ; Scroll table
         LDY #$FFE0      ; X: -32 = 480
         STY $35         ; Set BG1 X-Pos
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 65: Fade in "Locke as"
C3E5B7:  LDY $20         ; Delay expired?
         BNE C3E5D4      ; Exit if not
         INC $26         ; Next: C3/E5C6
         LDA #$F0        ; Switch delay
         STA $20         ; Set for alias
         JMP C3E1DF      ; Queue fade-in

; 66: Switch Locke's names
C3E5C6:  LDY $20         ; Delay expired?
         BNE C3E5D4      ; Exit if not
         INC $26         ; Next: C3/E5D5
         JSR C3E206      ; Switch names
         LDA #$F0        ; Intro delay
         STA $20         ; Set for Celes
C3E5D4:  RTS

; 67: Show Celes's name, fade Locke's
C3E5D5:  LDY $20         ; Delay expired?
         BNE C3E5F4      ; Exit if not
         STY $3F         ; BG3 Y-Pos: 0
         LDA #$06        ; Actor: Celes
         STA $28         ; Set actor slot
         JSR C3E897      ; Create "as"
         JSR C3E255      ; Fade Locke
         JSR C3DF5F      ; Create Celes
         JSR C3E1DF      ; Fade in Celes
         INC $26         ; Next: C3/E5F5
         LDA #$78        ; Removal delay
         STA $20         ; Set for Locke
C3E5F4:  RTS

; 68: Delete Locke's name
C3E5F5:  LDY $20         ; Delay expired?
         BNE C3E604      ; Exit if not
         INC $47         ; Erase name: Y
         INC $26         ; Next: C3/E605
         LDA #$B4        ; Switch delay
         STA $20         ; Set for Celes
C3E604:  RTS

; 69: Switch Celes's names
C3E605:  LDY $20         ; Delay expired?
         BNE C3E604      ; Exit if not
         INC $26         ; Next: C3/E61E
         LDA #$B4        ; Frames: 180
         STA $20         ; Set fade delay
         STZ $47         ; Erase name: N
         LDY #$0014      ; Frames: 20
         STY $85         ; Set scroll delay
         JSR C3E022      ; Create true name
         JMP C3E206      ; Switch names

; 6A: Fade all but Celes's name
C3E61E:  LDY $20         ; Delay expired?
         BNE C3E604      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
;        JSR C3E29E      ; No sprites...
         JMP C3E845      ; Scroll table

; 6E: Start Relm's scene
C3E635:  LDA #$08        ; Actor: Relm
         JSR C3E0B9      ; Init BGs/font
         JSR C3F00D      ; Draw brush; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E468      ; Fade in glint
         JSR C3E83F      ; Scroll table
         LDY #C3EC48     ; C3/EC48
         JSR qanim0      ; Queue glints
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 6F: Fade in "Relm as"
C3E651:  LDY $20         ; Delay expired?
         BNE C3E65F      ; Exit if not
         INC $26         ; Next: C3/E660
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E65F:  RTS

; 70: Switch Relm's names
C3E660:  LDY $20         ; Delay expired?
         BNE C3E66E      ; Exit if not
         INC $26         ; Next: C3/E66F
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E66E:  RTS

; 71: Fade all but Relm's name
C3E66F:  LDY $20         ; Delay expired?
         BNE C3E66E      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade glint
         JMP C3E845      ; Scroll table

; 78: Start Strago's scene
C3E686:  LDA #$07        ; Actor: Strago
         JSR C3E0B9      ; Init BGs/font
         JSR C3F023      ; Draw book
         JSR C3E192      ; Fade in BGs
         JSR C3ED7F      ; Queue book fn
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 79: Fade in "Strago as"
C3E69C:  LDY $20         ; Delay expired?
         BNE C3E6AA      ; Exit if not
         INC $26         ; Next: C3/E6AB
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E6AA:  RTS

; 7A: Switch Strago's names
C3E6AB:  LDY $20         ; Delay expired?
         BNE C3E6B9      ; Exit if not
         INC $26         ; Next: C3/E6BA
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E6B9:  RTS

; 7B: Fade all but Strago's name
C3E6BA:  LDY $20         ; Delay expired?
         BNE C3E6B9      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
;        JSR C3E29E      ; No sprites...
         JMP C3E145      ; Fade BGs

; 2D: Start first book scene
C3E6CE:  JSR C3E0B9      ; Init BGs/font
         JSR C3F023      ; Draw book
         JSR C3E192      ; Fade in BGs
         LDY #$02D0      ; Frames: 720
         STY $20         ; Set anim delay
         JMP C3E13D      ; Queue BG1, etc.

; 2E: Animate first book
C3E6DF:  LDY $20         ; Delay expired?
         BNE C3E6ED      ; Exit if not
         INC $26         ; Next: C3/E6EE
         JSR C3ED94      ; Queue book fn
         LDY #$01E0      ; Frames: 480
         STY $20         ; Set wait timer
C3E6ED:  RTS

; 2F: Wait 480 frames
C3E6EE:  LDY $20         ; Delay expired?
         BNE C3E6F9      ; Exit if not
         INC $26         ; Next: C3/E6FA
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E6F9:  RTS

; 30: Pixelate and fade first book
C3E6FA:  LDY $20         ; Delay expired?
         BNE C3E6F9      ; Exit if not
         JSR C3E84B      ; Queue mosaic
         LDA #$78        ; Frames: 120x2
         STA $20         ; Set exit delay
         JSR C3E145      ; Fade BGs
         JMP C3E845      ; Scroll table

; 4A: Start last book scene
C3E711:  JSR C3E0B9      ; Init BGs/font
         JSR C3F023      ; Draw book
         JSR C3E192      ; Fade in BGs
         JSR C3EDA9      ; Queue book fn
         LDA #$B4        ; Frames: 180
         STA $20         ; Set wait timer
         STZ $47         ; Erase text: N
         JSR C3E098      ; Create "And you"
         JMP C3E13D      ; Queue BG1, etc.

; 4B: Wait 180 frames
C3E72A:  LDY $20         ; Delay expired?
         BNE C3E735      ; Exit if not
         INC $26         ; Next: C3/E736
         LDA #$EC        ; Freeze delay
         STA $20         ; Set for book
C3E735:  RTS

; 4C: Stop last book and fade in text
C3E736:  LDY $20         ; Delay expired?
         BNE C3E735      ; Exit if not
         LDA #$01        ; Last page: Y
         STA $99         ; Set book flag
         INC $26         ; Next: C3/E749
         LDY #$016C      ; Frames: 364
         STY $20         ; Set fade delay
         JMP C3E22D      ; Queue fade-in

; 4D: Pixelate and fade last book
C3E749:  LDY $20         ; Delay expired?
         BNE C3E735      ; Exit if not
         JSR C3E84B      ; Queue mosaic
         LDA #$78        ; Fade delay
         STA $20         ; Set for text
         JMP C3E145      ; Fade BGs

; 82: Start Setzer's scene
C3E75D:  LDA #$09        ; Actor: Setzer
         JSR C3E0B9      ; Init BGs/font
         JSR C3F036      ; Upload cards
         JSR C3E192      ; Fade in BGs
         LDY #$3189      ; To OBJ pal 2
         JSR black       ; Cards: Black
         LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3189      ; To OBJ pal 2
         LDX #$9774      ; C2/9774
         JSR slow2       ; Fade in cards
         JSR C3E839      ; Scroll table
         JSR C3E8E3      ; Create cards
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3E123      ; Create text

; 83: Fade in "Setzer as"
C3E794:  LDY $20         ; Delay expired?
         BNE C3E7A2      ; Exit if not
         INC $26         ; Next: C3/E7A3
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E7A2:  RTS

; 84: Switch Setzer's names
C3E7A3:  LDY $20         ; Delay expired?
         BNE C3E7B1      ; Exit if not
         INC $26         ; Next: C3/E7B2
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E7B1:  RTS

; 85: Fade background
C3E7B2:  LDY $20         ; Delay expired?
         BNE C3E7B1      ; Exit if not
         INC $26         ; Next: C3/E7C1
         LDA #$78        ; Fade delay
         STA $20         ; Set for cards
         JMP C3E145      ; Fade BGs

; 86: Fade cards and name
C3E7C1:  LDY $20         ; Delay expired?
         BNE C3E7B1      ; Exit if not
         LDA #$78        ; Frames: 120
         STA $20         ; Set exit delay
         LDA #$01        ; C3/C5D4
         STA $26         ; Next: Exit
         JSR C3E255      ; Fade name
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3189      ; To OBJ pal 2
         LDX #C310F4     ; Black palette
         JMP slow4       ; Fade cards

; 87: Start Umaro's scene
C3E7E5:  LDA #$0D        ; Actor: Umaro
         JSR C3E0B9      ; Init BGs/font
         JSR C3F072      ; Draw bones; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in sprites
         JSR C3E83F      ; Scroll table
         JSR C3E8C4      ; Create skull
         JSR C3EA7C      ; Create moogles
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3E123      ; Create text

; 88: Fade in "Umaro as"
C3E804:  LDY $20         ; Delay expired?
         BNE C3E812      ; Exit if not
         INC $26         ; Next: C3/E813
         JSR C3E1DF      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3E812:  RTS

; 89: Switch Umaro's names
C3E813:  LDY $20         ; Delay expired?
         BNE C3E821      ; Exit if not
         INC $26         ; Next: C3/E822
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E821:  RTS

; 8A: Fade all but Umaro's name
C3E822:  LDY $20         ; Delay expired?
         BNE C3E821      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade sprites
;        BRA C3E845      ; Scroll table

; Set to scroll BG1 westward for 3 seconds
C3E845:  LDY #$00B4      ; Frames: 180
C3DFED:  PHY             ; Save timer
         LDY #C3E002     ; C3/E002
         JSR qanim0      ; Queue anim fn
         REP #$20        ; 16-bit A
         PLA             ; Scroll timer
         STA $7E3349,X   ; Set mode timer
         SEP #$20        ; 8-bit A
         RTS

; Set to scroll BG1 westward for 20 seconds
C3E839:  LDY #$04B0      ; Frames: 1200
         BRA C3DFED      ; Queue panning

; Set to scroll BG1 westward for 5.2 seconds
C3E83F:  LDY #$0138      ; Frames: 312
         BRA C3DFED      ; Queue panning

; Queue mosaic effect for book
C3E84B:  LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd text
         LDY #C3E852     ; C3/E852
         JMP qanim0      ; Queue anim fn

; Handle mosaic effect for book
C3E852:  BNE C3E865      ; If mode 1

; Mode 0: Initialize mosaic
C3E85A:  INC $3649,X     ; Mode +1
         STZ $33CA,X     ; Intensity: 0
         STZ $3349,X     ; Wait timer: 0

; Mode 1: Sustain mosaic
C3E865:  LDA $3349,X     ; Delay expired?
         BEQ C3E871      ; Proceed if so
         DEC $3349,X     ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3E871:  LDA $33CA,X     ; Intensity
         ORA #$0F        ; Layers: All
         STA $B5         ; Set mosaic
         LDA $33CA,X     ; Intensity
         CLC             ; Prepare ADC
         ADC #$10        ; Intensity +1
         STA $33CA,X     ; Save changes
         LDA #$10        ; Frames: 16
         STA $3349,X     ; Set next wait
         SEC             ; Set to requeue
         RTS

; Create "as"
C3E897:  LDY #C3DE84     ; C3/DE84
         JSR qanim3      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$0258      ; Frames: 600
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
         PEA $C079       ; Pos: 121, 192
         PEA $8E38       ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3E9DX      ; Set sprite's

; Create Umaro's skull
C3E8C4:  LDA #$CF        ; Anim ptr HB
         LDY #$F56E      ; Anim ptr LBs
         LDX #$4FC4      ; Pos: 196, 79
         JSR C3E9D2      ; Create sprite
         JMP C3EA6C      ; Follow BG1: Y

; Create four playing cards
C3E8E3:  LDX #$5078      ; Pos: 120, 80
         LDY #$0020      ; H-Spd: +0.125 px
         PEA $0080       ; V-Spd: +0.5 px
         JSR C3E97A      ; Create card 1
         LDX #$C048      ; Pos: 72, 192
         LDY #$0040      ; H-Spd: +0.25 px
         PEA $0060       ; V-Spd: +0.375 px
         JSR C3E97A      ; Create card 2
         LDX #$1098      ; Pos: 152, 16
         LDY #$FFE0      ; H-Spd: -0.125 px
         PEA $0080       ; V-Spd: +0.5 px
         JSR C3E97A      ; Create card 3
         LDX #$80D0      ; Pos: 208, 128
         LDY #$00A0      ; H-Spd: +0.625 px
         PEA $0080       ; V-Spd: +0.5 px
         JSR C3E97A      ; Create card 4
         RTS             ; ^ Avoid JMP

; Create current playing card
C3E97A:  PHY             ; Save H-Speed
         PHX             ; Save position
         SEP #$20        ; 8-bit A
         LDY #C3DEAB     ; C3/DEAB
         JSR qanim0      ; Queue anim fn
         LDA #$C2        ; Anim ptr HB
         LDY #$92FA      ; Anim ptr LBs
         JSR anm_st      ; Set card's
         PLY             ; Position
         JSR objpos      ; Set cards's
         REP #$20        ; 16-bit A
         PLA             ; H-Speed
         STA $7E34C9,X   ; Set card's
         PLY             ; Return adr
         PLA             ; V-Speed
         STA $7E3549,X   ; Set card's
         PHY             ; Repush adr
         SEP #$20        ; 8-bit A
         RTS

; Create face in Gau's diving helmet
C3E994:  LDA #$CF        ; Anim ptr HB
         LDY #$F647      ; Anim ptr LBs
         LDX #$5FCB      ; Pos: 203, 95
         JSR C3E9D2      ; Create sprite
         BRA C3EA6C      ; Follow BG1: Y

; Create Shadow's apple
C3E9B3:  LDA #$C2        ; Anim ptr HB
         LDY #$9497      ; Anim ptr LBs
         LDX #$57C0      ; Pos: 192, 87
         JSR C3E9D2      ; Create sprite
         BRA C3EA6C      ; Follow BG1: Y

; Create glowing eye in Gogo's helmet
C3E9E4:  LDA #$CF        ; Anim ptr HB
         LDY #$F450      ; Anim ptr LBs
         LDX #$61C8      ; Pos: 200, 97
         JSR C3E9D2      ; Create sprite
         BRA C3EA6C      ; Follow BG1: Y

; Create glint on Terra's pendant
C3EA03:  LDA #$CF        ; Anim ptr HB
         LDY #$F5B4      ; Anim ptr LBs
         LDX #$6080      ; Pos: 128, 96
;        BRA C3E9D2      ; Create sprite

; Queue regular permanent sprite
C3E9D2:  PHX             ; Save position
         PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3DEAB     ; C3/DEAB
         JSR qanim3      ; Queue OAM fn
C3E9DX:  PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
C3E9DY:  PLY             ; Position
         JMP objpos      ; Set sprite's

; Set sprite to pan with BG1, define Y position
C3EA68:  STA $7E344A,X   ; Set Y position
C3EA6C:  LDA #$01        ; Pans with BG1
         STA $7E364A,X   ; Set sprite flags
         RTS

; Create Mog's mini moogles and winding key
C3EA24:  LDA #$CF        ; Anim ptr HB
         LDY #$F515      ; Anim ptr LBs
         LDX #$6FE0      ; Pos: 224, 111
         JSR C3E9D2      ; Create key
         JSR C3EA6C      ; Follow BG1: Y
         LDA #$BA        ; X: 186
         JSR C3EA73      ; Queue moogle 1
         LDA #$C6        ; X: 198
         JSR C3EA73      ; Queue moogle 2
         LDA #$D1        ; X: 209
         JSR C3EA73      ; Queue moogle 3
         LDA #$DC        ; X: 220
;        BRA C3EA73      ; Queue moogle 4

; Queue current mini moogle
C3EA73:  PHA             ; Save X pos
         LDY #C3EAFC     ; C3/EAFC
         JSR qanim2      ; Queue OAM fn
         PLA             ; X position
         STA $7E33CA,X   ; Set moogle's
         RTS

; Create Umaro's moogles
C3EA7C:  LDY #$01A4      ; Walk timer: 420
         LDX #$F47F      ; Bump anim ptr
         LDA #$3A        ; Base X: 58
         JSR C3EA7_      ; Create moogle 1
         LDY #$01B8      ; Walk timer: 440
         LDX #$F485      ; Bump anim ptr
         LDA #$2E        ; Base X: 46
         JSR C3EA7_      ; Create moogle 2
         LDA #$21        ; Base X: 33
         LDY #$01CC      ; Walk timer: 460
         LDX #$F48B      ; Bump anim ptr
         JSR C3EA7_      ; Create moogle 3
         LDY #$01E0      ; Walk timer: 480
         LDX #$F491      ; Bump anim ptr
         LDA #$14        ; Base X: 20
;        BRA C3EA7_      ; Create moogle 4

; Create mini moogle for Umaro's scene
C3EA7_:  PHX             ; Save pointer
         PHY             ; Save timer
         JSR C3EA73      ; Queue OAM fn
         LDA #$05        ; Approach bones
         STA $7E3649,X   ; Set anim mode
         REP #$20        ; 16-bit A
         PLA             ; Walk timer
         STA $7E3349,X   ; Set moogle's
         PLA             ; Bump anim ptr
         STA $7E37C9,X   ; Set moogle's
         SEP #$20        ; 8-bit A
         RTS

; Animate mini moogle
C3EAFC:  TAX             ; Index mode
         JMP (C3EB00,X)  ; Handle mode

; Jump table
C3EB00:  dw C3EB10       ; Initialize data
         dw C3EB35       ; Spin around
         dw C3EB5E       ; Face left
         dw C3EB7B       ; Jump down
         dw C3EB97       ; Walk away from tree
         dw C3EB9C       ; Initialize data
         dw C3EBA9       ; Walk toward bones
         dw C3EBD0       ; Stop and fall down

; Mode 0: Initialize data
C3EB10:  LDX $2D         ; Queue index
         LDA #$CF        ; Anim ptr HB
         LDY #$F458      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         INC $3649,X     ; Mode +1
         LDA #$64        ; Y: 100
         JSR C3EA68      ; Set Y, pan flag
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set spin timer
         JSR C31206      ; Set pose timer

; Mode 1: Spin around
C3EB35:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EB56      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         LDY #$F47C      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDA #$10        ; Frames: 16
         STA $3349,X     ; Set jump timer
         JSR C31206      ; Set pose timer
C3EB56:  JSR C3CFE5      ; Mode timer -1
         BRA C3EBD0      ; Scroll & OAM

; Mode 2: Jump down
C3EB5E:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EB6D      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$3C        ; Frames: 60
         STA $3349,X     ; Set walk delay
C3EB6D:  JSR C3CFE5      ; Mode timer -1
         JSR C3EBF0      ; Adjust Y-Pos
         INC $35C9,X     ; Y-Pos mod +1
         BRA C3EBD0      ; Scroll & OAM

; Mode 3: Face left
C3EB7B:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EB8F      ; Branch if not
         JSR C3EBD5      ; Set to walk
C3EB8F:  JSR C3CFE5      ; Mode timer -1
;        BRA C3EBD0      ; Scroll & OAM

; Mode 4: Walk away from tree
C3EB97:  BRA C3EBD0      ; Scroll & OAM

; Mode 5: Initialize data
C3EB9C:  LDX $2D         ; Queue index
         JSR C3EBD5      ; Set to walk
         LDA #$70        ; Y: 112
         JSR C3EA68      ; Set Y, pan flag

; Mode 6: Walk toward bones
C3EBA9:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EBC8      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         LDY $37C9,X     ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
;        REP #$20        ; 16-bit A
         STZ $34C9,X     ; H-Speed: 0
         JSR C31206      ; Set pose timer
C3EBC8:  JSR C3CFE5      ; Mode timer -1
;        BRA C3EBD0      ; Scroll & OAM

; Mode 7: Stop and fall down
C3EBD0:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Set mini moogle to walk eastward
C3EBD5:  INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         LDY #$F473      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         REP #$20        ; 16-bit A
         LDA #$0040      ; H-Spd: +0.25 px
         STA $34C9,X     ; Set sprite's
         JMP C31206      ; Set pose timer

; Adjust jumping mini moogle's Y position
C3EBF0:  LDA $35C9,X     ; Modifier index
;        AND #$0F        ; ...
         TAX             ; Index it
         LDA $CFF55E,X   ; Y modifier
         LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $344A,X     ; Add sprite's Y
         STA $344A,X     ; Set sprite's Y
         RTS

; Queue brush or katana glint
C3EC3F:  PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         PHB             ; Save DB
         LDY #C3ED14     ; C3/ED14
         JSR qanim2      ; Queue anim fn
         PLB             ; Restore DB
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JMP anm_st      ; Set glint's

; Create a series of glints on Relm's brush
C3EC48:  BNE C3EC67      ; If mode 1

; Mode 0: Initialize wave
C3EC50:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set wave delay
         SEP #$20        ; 8-bit A
         LDA #$E4        ; X: 228
         STA $C7         ; Set base X
         LDA #$03        ; Glints: 3
         STA $C9         ; Set counter

; Mode 1: Create wave
C3EC67:  LDA $C9         ; Glints left
         BEQ C3ED12      ; Dequeue if 0
         LDY $3349,X     ; Delay expired?
         BNE C3ED0D      ; Branch if not
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set next delay
         LDA #$CF        ; Anim ptr HB
         LDY #$F5B4      ; Anim ptr LBs
         JSR C3EC3F      ; Queue glint
         LDA #$68        ; Y = 104
         BRA glints      ; X = $C7

; Create a series of glints on Cyan's katana
C3ECAE:  BNE C3ECCD      ; If mode 1

; Mode 0: Initialize wave
C3ECB6:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set wave delay
         SEP #$20        ; 8-bit A
         LDA #$C8        ; X: 200
         STA $C7         ; Set base X
         LDA #$04        ; Glints: 4
         STA $C9         ; Set counter

; Mode 1: Create wave
C3ECCD:  LDA $C9         ; Glints left
         BEQ C3ED12      ; Dequeue if 0
         LDY $3349,X     ; Delay expired?
         BNE C3ED0D      ; Branch if not
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set next delay
         LDA #$CF        ; Anim ptr HB
         LDY #$F5FA      ; Anim ptr LBs
         JSR C3EC3F      ; Queue glint
         LDA #$60        ; Y: 96
glints:  STA $344A,X     ; Set glint's
         LDA $C7         ; Base X
         STA $33CA,X     ; Set glint's
         DEC A           ; Base X -1
         DEC A           ; Base X -1
         DEC A           ; Base X -1
         DEC A           ; Base X -1
         STA $C7         ; Save changes
         DEC $C9         ; Glints left -1
C3ED0D:  JSR C3CFE5      ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3ED12:  CLC             ; Set to dequeue
         RTS

; Animate glint on brush or katana
C3ED14:  BNE C3ED29      ; If mode 1

; Mode 0: Initialize sprite
C3ED1C:  JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         JSR C3EA6C      ; Follow BG1: Y

; Mode 1: Sustain sprite
C3ED29:  LDA $36CA,X     ; Pose timer
         CMP #$FE        ; Set as endless?
         BEQ C3ED37      ; Delete if so
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3ED37:  CLC             ; Set to dequeue
         RTS

; Animate double-headed coin
C3ED39:  BNE C3ED6D      ; If mode 1

; Mode 0: Initialize sprite
C3ED41:  INC $3649,X     ; Mode +1
         LDA #$D8        ; Anim ptr HB
         LDY #$EC93      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDA #$C8        ; Frames: 200
         STA $3349,X     ; Set roll timer
         LDY #$6410      ; Pos: 16, 100
         JSR objpos      ; Set sprite's
         REP #$20        ; 16-bit A
         LDA #$0080      ; H-Spd: +0.5 px
         STA $34C9,X     ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3ED6D:  LDA $3349,X     ; Stop rolling?
         BNE C3ED77      ; Branch if not
         STZ $34C9,X     ; H-Speed: 0
C3ED77:  DEC $3349,X     ; Roll timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Set to animate Strago's book
C3ED7F:  LDA #$C2        ; Anim ptr HB
         LDY #$8B72      ; Anim ptr LBs
         BRA C3EDBE      ; Queue anim fn

; Set to animate first book
C3ED94:  LDA #$C2        ; Anim ptr HB
         LDY #$8B63      ; Anim ptr LBs
         BRA C3EDBE      ; Queue anim fn

; Set to animate last book
C3EDA9:  LDA #$C2        ; Anim ptr HB
         LDY #$8B45      ; Anim ptr LBs

; Set to animate book
C3EDBE:  PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         STZ $99         ; Last page: N
         LDY #C3EE04     ; C3/EE04
         JSR qanim1      ; Queue anim fn
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JMP anm_st      ; Set book's

; Integrate decompressed tilemap segment, adjust attributes
C3EDCD:  STX $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDX $00         ; Rows done: 0
         REP #$20        ; 16-bit A
C3EDDD:  TDC             ; Clear A
         TAY             ; Index: 0
C3EDDF:  LDA [$E7],Y     ; Attributes
;        CLC             ; Prepare ADC
;        ADC $60         ; Always 0...
         STA [$EB],Y     ; Put in map
         INY             ; Index +1
         INY             ; Index +1
         CPY $E0         ; End of row?
         BNE C3EDDF      ; Loop if not
         LDA $E7         ; Source LBs
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $E7         ; Save changes
         LDA $EB         ; Dest LBs
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $EB         ; Save changes
         INX             ; Rows done +1
         CPX $E2         ; More left?
         BNE C3EDDD      ; Loop if so
         SEP #$20        ; 8-bit A
         RTS

; Animate book
C3EE04:  CMP #$02        ; Mode 1?
         BEQ C3EE18      ; Branch if so
         BCS C3EE1C      ; If mode 2

; Mode 0: Initialize timer
C3EE0E:  JSR C3120_      ; Set pose timer
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 1: Check if last page
C3EE18:  LDA $99         ; Last page?
         BEQ C3EE1C      ; Branch if not

; Fork: Set to stop animation
C3EE59:  LDA #$C2        ; Anim ptr HB
         LDY #$8B54      ; Anim ptr LBs
         JSR anm_st      ; Set book's
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer

; Mode 2: Update tilemap
C3EE1C:  JSR C31227      ; Pose timer -1
         LDX $2D         ; Queue index
         LDA $35CA,X     ; Anim ptr HB
         STA $E9         ; Set src HB
         TDC             ; Clear A
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Pose info loc
         STA $E7         ; Set src LBs
         LDA [$E7]       ; Column count
         STA $E0         ; Set width
         LDY #$0002      ; Src index
         LDA [$E7],Y     ; Row count
         STA $E2         ; Set height
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Source LBs
         TAX             ; Put in X
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Dest LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         JSR C3EDCD      ; Replace tiles
         SEC             ; Set to requeue
         RTS

; Unpack and upload large font graphics for actor scene
C3EE74:  LDY #$BA00      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack GFX
         JSR C3D518      ; Src: 7E/C000
         LDX #$0900      ; Bytes: 2304
         LDY #$7000      ; VRAM pointer
         JMP C3DD86      ; Upload GFX

; Unpack and upload BG graphics and tilemaps for actor scene
C3EE90:  LDY #$C008      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack data

; Fork: Copy table's map to BG1 tilemap A
C3EE98:  LDY #$3849      ; Tilemap ptr
         JSR C3EF10      ; Move data

; Fork: Copy table's map to BG1 tilemap B
C3EEA4:  LDY #$4049      ; Tilemap ptr
         JSR C3EF10      ; Move data

; Fork: Upload tall items and table side graphics
C3EEB0:  JSR C3D518      ; Src: 7E/C000
         LDX #$1F60      ; Bytes: 8032
         LDY #$3000      ; VRAM pointer
         JSR C3DDB_      ; Upload data

; Fork: Upload large items, tabletop, and overlay graphics
C3EEC8:  LDY #$DF60      ; 7E/DF60
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDX #$0B40      ; Bytes: 2880
         LDY #$4000      ; VRAM pointer
         JSR C3DDB_      ; Upload data

; Fork: Upload book graphics
C3EEE0:  LDY #$EAA0      ; 7E/EAA0
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDX #$0E00      ; Bytes: 3584
         LDY #$5000      ; VRAM pointer
         JSR C3DDB_      ; Upload data

; Fork: Upload transparent overlay tilemap (BG2)
C3EEF8:  LDY #$0448      ; 7F/0448
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDX #$0780      ; Bytes: 1920
         LDY #$1000      ; VRAM pointer
         JMP C3DDB_      ; Upload data

; Relocate decompressed tilemap for table
C3EF10:  STY $EB         ; Set dst LBs
         LDY #$F8A0      ; 7E/F8A0
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         STA $ED         ; Set dst HB
         LDY #$0780      ; Bytes: 1920
         JMP C3D6EE      ; Move data

; Set to upload BG1 and BG3 tilemaps for actor scene
C3EF21:  LDY #$1800      ; $1800
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         JMP C30EE9      ; Handle BG1

; Unpack and upload apple and shuriken graphics
C3EF48:  LDY #$F477      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack GFX
         JSR C3D518      ; Src: 7E/C000
         LDX #$0380      ; Bytes: 896
         LDY #$6000      ; VRAM pointer
         JMP C3DDB_      ; Upload GFX

; Draw Cyan's katana; unpack and upload glint
C3EF68:  JSR C3F036      ; Handle glint
         LDY #$0026      ; Tiles: 19
         STY $E0         ; Set width
         LDY #$0002      ; Tiles: 2
         STY $E2         ; Set height
         LDX #$03E0      ; Src: 7F/03E0
         LDY #$3BA1      ; Dst: 7E/3BA1
         JMP C3EDCD      ; Draw katana

; Unpack and upload coin graphics
C3EF7E:  JSR C3EF87      ; Unpack data
         LDY #$6000      ; VRAM pointer
         JMP C3DDB_      ; Upload data

; Unpack skull and coin graphics; prepare upload
C3EF87:  LDY #$9D4B      ; Source LBs
         LDA #$D9        ; Source HB
         JSR C3DD61      ; Unpack GFX
         LDX #$0800      ; Bytes: 896
         JMP C3D518      ; Src: 7E/C000

; Draw Mog's tree; unpack and upload sprites
C3EFA2:  JSR C3F036      ; Do sprites
         LDY #$000E      ; Tiles: 7
         STY $E0         ; Set width
         LDY #$0008      ; Tiles: 8
         STY $E2         ; Set height
         LDX #$0020      ; Src: 7F/0020
         LDY #$3A77      ; Dst: 7E/3A77
         JMP C3EDCD      ; Draw tree

; Draw Gogo's helmet; unpack and upload glint
C3EFB8:  JSR C3F036      ; Handle glint
         LDY #$001C      ; Tiles: 14
         STY $E0         ; Set width
         LDY #$0009      ; Tiles: 9
         STY $E2         ; Set height
         LDX #$002E      ; Src: 7F/002E
         LDY #$3A2D      ; Dst: 7E/3A2D
         JMP C3EDCD      ; Draw helmet

; Draw Gau's diving helmet; unpack and upload face
C3EFCE:  JSR C3F056      ; Handle face
         LDY #$000C      ; Tiles: 6
         STY $E0         ; Set width
         LDY #$0007      ; Tiles: 7
         STY $E2         ; Set height
         LDX #$004A      ; Src: 7F/004A
         LDY #$3AB7      ; Dst: 7E/3AB7
         JMP C3EDCD      ; Draw helmet

; Draw Terra's cocktail glasses; unpack and upload glint
C3EFE4:  JSR C3F036      ; Handle glint
         LDY #$000E      ; Tiles: 7
         STY $E0         ; Set width
         LDY #$0005      ; Tiles: 5
         STY $E2         ; Set height
         LDX #$0220      ; Src: 7F/0220
         LDY #$3B35      ; Dst: 7E/3B35
         JMP C3EDCD      ; Draw glasses

; Draw Locke and Celes's bouquet
C3EFFA:  LDY #$0018      ; Tiles: 12
         STY $E0         ; Set width
         LDY #$0006      ; Tiles: 6
         STY $E2         ; Set height
         LDX #$0274      ; Src: 7F/0274
         LDY #$3B69      ; Dst: 7E/3B69
         JMP C3EDCD      ; Replace tiles

; Draw Relm's brush; unpack and upload glint
C3F00D:  JSR C3F036      ; Handle glint
         LDY #$0014      ; Tiles: 10
         STY $E0         ; Set width
         LDY #$0002      ; Tiles: 2
         STY $E2         ; Set height
         LDX #$0360      ; Src: 7F/0360
         LDY #$3BF3      ; Dst: 7E/3BF3
         JMP C3EDCD      ; Draw brush

; Draw an open book
C3F023:  LDY #$001C      ; Tiles: 14
         STY $E0         ; Set width
         LDY #$0006      ; Tiles: 6
         STY $E2         ; Set height
         LDX #$0BC8      ; Src: 7F/0BC8
         LDY #$3AD9      ; Dst: 7E/3AD9
         JMP C3EDCD      ; Replace tiles

; Unpack and upload card, glint, moogle, and winding key graphics
C3F036:  LDY #$F6FB      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack GFX
         JSR C3D518      ; Src: 7E/C000
         LDX #$0DF0      ; Bytes: 3568
         LDY #$6000      ; VRAM pointer
         JMP C3DDB_      ; Upload GFX

; Unpack and upload face graphics for Gau's scene
C3F056:  LDY #$A4E5      ; Source LBs
         LDA #$D9        ; Source HB
         JSR C3DD61      ; Unpack GFX
         JSR C3D518      ; Src: 7E/C000
         LDX #$00C0      ; Bytes: 192
         LDY #$6000      ; VRAM pointer
         JMP C3DD86      ; Upload GFX

; Draw Umaro's bones; unpack and upload sprites
C3F072:  JSR C3F036      ; Handle moogles
         JSR C3EF87      ; Unpack skull
         LDY #$6800      ; VRAM pointer
         JSR C3DDB_      ; Upload skull
         LDY #$000A      ; Tiles: 5
         STY $E0         ; Set width
         LDY #$0005      ; Tiles: 5
         STY $E2         ; Set height
         LDX #$0056      ; Src: 7F/0056
         LDY #$3B37      ; Dst: 7E/3B37
         JMP C3EDCD      ; Draw bones

; =========================[ Navigation parameters ]===========================

; Navigation data for Save menu
C315B3:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $03          ; 3 rows

; Navigation data for save file confirmation
C315E3:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $02          ; 2 rows

; Navigation data for Load menu
C315C7:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for main menu
C32F85:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for non-shifted Status menu
C3370E:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for Config page 1
C33867:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $09          ; 9 rows

; Navigation data for Config page 2
C3388D:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $06          ; 6 rows

; Navigation data for Rage menu
C34C5B:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $08          ; 8 rows

; Navigation data for Cmd.Set menu's actor list
C345C5:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $05          ; 5 rows

; Navigation data for Cmd.Set menu's command list
C3464A:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for Controller menu
C348E6:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for Skills menu
C34B6F:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $01          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for Magic menu
C34BA9:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $08          ; 8 rows

; Navigation data for SwdTech, Blitz, and Dance menus
C34BDF:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $04          ; 4 rows

; Navigation data for Lore menu
C34C03:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $08          ; 8 rows

; Navigation data for Espers menu
C34C27:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $08          ; 8 rows

; Navigation data for esper data menu
C3598C:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for shifted Status menu
C36412:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $10          ; 16 rows

; Navigation data for actor naming menu
C36647:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $0A          ; 10 columns
         db $07          ; 7 rows

; Navigation data for non-party area of Lineup menu
C374BE:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $08          ; 8 columns
         db $02          ; 2 rows

; Navigation data for single-party area of Lineup menu
C374E3:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $02          ; 2 rows

; Navigation data for two-party area of Lineup menu
C374F0:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $02          ; 2 rows

; Navigation data for three-party area of Lineup menu
C37505:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $06          ; 6 columns
         db $02          ; 2 rows

; Navigation data for Item, Colosseum, and Sell menus
C37D2B:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $0A          ; 10 rows

; Navigation data for rare item menu
C37D53:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $0A          ; 10 rows

; Navigation data for Item menu options
C37D98:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $01          ; 1 row

; Navigation data for Equip menu options
C38E5F:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $01          ; 1 row

; Navigation data for Equip menu slot selection
C38E7B:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for equipment list
C38EA6:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $09          ; 9 rows

; Navigation data for Relic menu options
C38ECC:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $01          ; 1 row

; Navigation data for relic slot selection
C38EE4:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $02          ; 2 rows

; Navigation data for final battle lineup
C3AC63:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $0E          ; 14 rows

; Navigation data for Colosseum matchup menu
C3B332:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $01          ; 1 row

; Navigation data for main shop menu
C3B895:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $01          ; 1 row

; Navigation data for Buy menu
C3B8AF:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $08          ; 8 rows

; Navigation data for portrait selection
C33042:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for portrait selection
C33047:  dw $2808        ; Member 1
         dw $5808        ; Member 2
         dw $8808        ; Member 3
         dw $B808        ; Member 4

; Cursor positions above must follow nav table.


; ============================[ Cursor positions ]=============================

; Cursor positions for Save and Load menus
C315CC:  dw $1C08        ; New Game
C315CE:  dw $3C08        ; Save file 1
         dw $7408        ; Save file 2
         dw $AC08        ; Save file 3

; Cursor positions for save file confirmation
C315E8:  dw $44BF        ; Yes
         dw $54BF        ; No

; Cursor positions for main menu
C32F8A:  dw $12AF        ; Item
         dw $21AF        ; Skills
         dw $30AF        ; Equip
         dw $3FAF        ; Relic
         dw $4EAF        ; Status
         dw $5DAF        ; Config
         dw $6CAF        ; Save

; Cursor positions for non-shifted Status menu
C33713:  dw $5990        ; Command 1
         dw $6590        ; Command 2
         dw $7190        ; Command 3
         dw $7D90        ; Command 4

; Cursor positions for Config page 1
C3386C:  dw $2960        ; Bat.Mode
         dw $3960        ; Bat.Speed
         dw $4960        ; Msg.Speed
         dw $5960        ; Cmd.Set
         dw $6960        ; Gauge
         dw $7960        ; Sound
         dw $8960        ; Cursor
         dw $9960        ; Reequip
         dw $A960        ; Controller

; Cursor positions for Config page 2
C33892:  dw $2960        ; Mag.Order
         dw $6960        ; Window
         dw $7960        ; Color
         dw $9960        ; R
         dw $A960        ; G
         dw $B960        ; B

; Cursor positions for Cmd.Set menu's actor list
C345CA:  dw $2008        ; Member 1
         dw $5008        ; Member 2
         dw $8008        ; Member 3
         dw $B008        ; Member 4
         dw $0C08        ; Arrange

; Cursor positions for member 1 in Cmd.Set menu
C3464F:  dw $2080        ; Command 1
         dw $2C58        ; Command 2
         dw $2CA8        ; Command 3
         dw $3880        ; Command 4

; Cursor positions for member 2 in Cmd.Set menu
C34657:  dw $5080        ; Command 1
         dw $5C58        ; Command 2
         dw $5CA8        ; Command 3
         dw $6880        ; Command 4

; Cursor positions for member 3 in Cmd.Set menu
C3465F:  dw $8080        ; Command 1
         dw $8C58        ; Command 2
         dw $8CA8        ; Command 3
         dw $9880        ; Command 4

; Cursor positions for member 4 in Cmd.Set menu
C34667:  dw $B080        ; Command 1
         dw $BC58        ; Command 2
         dw $BCA8        ; Command 3
         dw $C880        ; Command 4

; Cursor positions for Controller menu
C348EB:  dw $7B50        ; Member 1
         dw $8B50        ; Member 2
         dw $9B50        ; Member 3
         dw $AB50        ; Member 4

; Cursor positions for Skills menu
C34B74:  dw $1400        ; Espers
         dw $2400        ; Magic
         dw $4400        ; SwdTech
         dw $5400        ; Blitz
         dw $6400        ; Lore
         dw $7400        ; Rage
         dw $8400        ; Dance

; Cursor positions for Magic menu
C34BAE:  dw $7408        ; Spell 1
         dw $7470        ; Spell 2
         dw $8008        ; Spell 3
         dw $8070        ; Spell 4
         dw $8C08        ; Spell 5
         dw $8C70        ; Spell 6
         dw $9808        ; Spell 7
         dw $9870        ; Spell 8
         dw $A408        ; Spell 9
         dw $A470        ; Spell 10
         dw $B008        ; Spell 11
         dw $B070        ; Spell 12
         dw $BC08        ; Spell 13
         dw $BC70        ; Spell 14
         dw $C808        ; Spell 15
         dw $C870        ; Spell 16

; Cursor positions for SwdTech, Blitz, and Dance menus
C34BE4:  dw $7408        ; Skill 1
         dw $7478        ; Skill 2
         dw $8C08        ; Skill 3
         dw $8C78        ; Skill 4
         dw $A408        ; Skill 5
         dw $A478        ; Skill 6
         dw $BC08        ; Skill 7
         dw $BC78        ; Skill 8

; Cursor positions for Lore menu
C34C08:  dw $7408        ; Spell 1
         dw $8008        ; Spell 2
         dw $8C08        ; Spell 3
         dw $9808        ; Spell 4
         dw $A408        ; Spell 5
         dw $B008        ; Spell 6
         dw $BC08        ; Spell 7
         dw $C808        ; Spell 8

; Cursor positions for Espers menu
C34C2C:  dw $7408        ; Esper 1
         dw $7478        ; Esper 2
         dw $8008        ; Esper 3
         dw $8078        ; Esper 4
         dw $8C08        ; Esper 5
         dw $8C78        ; Esper 6
         dw $9808        ; Esper 7
         dw $9878        ; Esper 8
         dw $A408        ; Esper 9
         dw $A478        ; Esper 10
         dw $B008        ; Esper 11
         dw $B078        ; Esper 12
         dw $BC08        ; Esper 13
         dw $BC78        ; Esper 14
         dw $C808        ; Esper 15
         dw $C878        ; Esper 16

; Cursor positions for Rage menu
C34C60:  dw $7418        ; Rage 1
         dw $7488        ; Rage 2
         dw $8018        ; Rage 3
         dw $8088        ; Rage 4
         dw $8C18        ; Rage 5
         dw $8C88        ; Rage 6
         dw $9818        ; Rage 7
         dw $9888        ; Rage 8
         dw $A418        ; Rage 9
         dw $A488        ; Rage 10
         dw $B018        ; Rage 11
         dw $B088        ; Rage 12
         dw $BC18        ; Rage 13
         dw $BC88        ; Rage 14
         dw $C818        ; Rage 15
         dw $C888        ; Rage 16

; Cursor positions for esper data menu
C35991:  dw $7010        ; Esper
         dw $7C18        ; Spell A
         dw $8818        ; Spell B
         dw $9418        ; Spell C
         dw $A018        ; Spell D
         dw $AC18        ; Spell E
         dw $B818        ; Bonus

; Cursor positions for shifted Status menu
C36417:  dw $10F0        ; Empty
         dw $1CF0        ; Command 1
         dw $28F0        ; Command 2
         dw $34F0        ; Command 3
         dw $40F0        ; Command 4
         dw $4CF0        ; Command 5
         dw $58F0        ; Command 6
         dw $64F0        ; Command 7
         dw $70F0        ; Command 8
         dw $7CF0        ; Command 9
         dw $88F0        ; Command 10
         dw $94F0        ; Command 11
         dw $A0F0        ; Command 12
         dw $ACF0        ; Command 13
         dw $B8F0        ; Command 14
;        dw $C4F0        ; Command 15 (unused)

; Cursor positions for actor naming menu
C3664C:  dw $5838        ; A
         dw $5848        ; B
         dw $5858        ; C
         dw $5868        ; D
         dw $5878        ; E
         dw $5890        ; a
         dw $58A0        ; b
         dw $58B0        ; c
         dw $58C0        ; d
         dw $58D0        ; e
         dw $6838        ; F
         dw $6848        ; G
         dw $6858        ; H
         dw $6868        ; I
         dw $6878        ; J
         dw $6890        ; f
         dw $68A0        ; g
         dw $68B0        ; h
         dw $68C0        ; i
         dw $68D0        ; j
         dw $7838        ; K
         dw $7848        ; L
         dw $7858        ; M
         dw $7868        ; N
         dw $7878        ; O
         dw $7890        ; k
         dw $78A0        ; l
         dw $78B0        ; m
         dw $78C0        ; n
         dw $78D0        ; o
         dw $8838        ; P
         dw $8848        ; Q
         dw $8858        ; R
         dw $8868        ; S
         dw $8878        ; T
         dw $8890        ; p
         dw $88A0        ; q
         dw $88B0        ; r
         dw $88C0        ; s
         dw $88D0        ; t
         dw $9838        ; U
         dw $9848        ; V
         dw $9858        ; W
         dw $9868        ; X
         dw $9878        ; Y
         dw $9890        ; u
         dw $98A0        ; v
         dw $98B0        ; w
         dw $98C0        ; x
         dw $98D0        ; y
         dw $A838        ; Z
         dw $A848        ; !
         dw $A858        ; ?
         dw $A868        ; /
         dw $A878        ; :
         dw $A890        ; z
         dw $A8A0        ; ”
         dw $A8B0        ; ’
         dw $A8C0        ; -
         dw $A8D0        ; .
         dw $B838        ; 0
         dw $B848        ; 1
         dw $B858        ; 2
         dw $B868        ; 3
         dw $B878        ; 4
         dw $B890        ; 5
         dw $B8A0        ; 6
         dw $B8B0        ; 7
         dw $B8C0        ; 8
         dw $B8D0        ; 9

; Cursor positions for non-party area of Lineup menu
C374C3:  dw $6408        ; Slot 1
         dw $6424        ; Slot 2
         dw $6440        ; Slot 3
         dw $645C        ; Slot 4
         dw $6478        ; Slot 5
         dw $6494        ; Slot 6
         dw $64B0        ; Slot 7
         dw $64CC        ; Slot 8
         dw $8008        ; Slot 9
         dw $8024        ; Slot 10
         dw $8040        ; Slot 11
         dw $805C        ; Slot 12
         dw $8078        ; Slot 13
         dw $8094        ; Slot 14
         dw $80B0        ; Slot 15
         dw $80CC        ; Slot 16

; Cursor positions for single-party area of Lineup menu
C374E8:  dw $A408        ; NW
         dw $A428        ; NE
         dw $C008        ; SW
         dw $C028        ; SE

; Cursor positions for two-party area of Lineup menu
C374F5:  dw $A408        ; Party 1, NW
         dw $A428        ; Party 1, NE
         dw $A458        ; Party 2, NW
         dw $A478        ; Party 2, NE
         dw $C008        ; Party 1, SW
         dw $C028        ; Party 1, SE
         dw $C058        ; Party 2, SW
         dw $C078        ; Party 2, SE

; Cursor positions for three-party area of Lineup menu
C3750A:  dw $A408        ; Party 1, NW
         dw $A428        ; Party 1, NE
         dw $A458        ; Party 2, NW
         dw $A478        ; Party 2, NE
         dw $A4A8        ; Party 3, NW
         dw $A4C8        ; Party 3, NE
         dw $C008        ; Party 1, SW
         dw $C028        ; Party 1, SE
         dw $C058        ; Party 2, SW
         dw $C078        ; Party 2, SE
         dw $C0A8        ; Party 3, SW
         dw $C0C8        ; Party 3, SE

; Cursor positions for Item, Colosseum, and Sell menus
C37D30:  dw $5C08        ; Item 1
         dw $6808        ; Item 2
         dw $7408        ; Item 3
         dw $8008        ; Item 4
         dw $8C08        ; Item 5
         dw $9808        ; Item 6
         dw $A408        ; Item 7
         dw $B008        ; Item 8
         dw $BC08        ; Item 9
         dw $C808        ; Item 10

; Cursor positions for rare item menu
C37D58:  dw $5C08        ; Item 1
         dw $5C78        ; Item 2
         dw $6808        ; Item 3
         dw $6878        ; Item 4
         dw $7408        ; Item 5
         dw $7478        ; Item 6
         dw $8008        ; Item 7
         dw $8078        ; Item 8
         dw $8C08        ; Item 9
         dw $8C78        ; Item 10
         dw $9808        ; Item 11
         dw $9878        ; Item 12
         dw $A408        ; Item 13
         dw $A478        ; Item 14
         dw $B008        ; Item 15
         dw $B078        ; Item 16
         dw $BC08        ; Item 17
         dw $BC78        ; Item 18
         dw $C808        ; Item 19
         dw $C878        ; Item 20

; Cursor positions for Item menu options
C37D9D:  dw $1640        ; USE
         dw $1668        ; ARRANGE
         dw $16B0        ; RARE

; Cursor positions for Equip menu options
C38E64:  dw $1000        ; EQUIP
         dw $1038        ; OPTIMUM
         dw $1080        ; RMOVE
         dw $10B8        ; EMPTY

; Cursor positions for Equip menu slot selection
C38E80:  dw $2C00        ; R-Hand
         dw $3800        ; L-Hand
         dw $4400        ; Head
         dw $5000        ; Body

; Cursor positions for equipment list
C38EAB:  dw $6800        ; Item 1
         dw $7400        ; Item 2
         dw $8000        ; Item 3
         dw $8C00        ; Item 4
         dw $9800        ; Item 5
         dw $A400        ; Item 6
         dw $B000        ; Item 7
         dw $BC00        ; Item 8
         dw $C800        ; Item 9

; Cursor positions for Relic menu options
C38ED1:  dw $1010        ; Equip
         dw $1048        ; Remove

; Cursor positions for relic slots
C38EE9:  dw $4400        ; Relic 1
         dw $5000        ; Relic 2

; Cursor positions for final battle lineup
C3AC68:  dw $2010        ; Reset
         dw $2C20        ; Actor 1
         dw $3820        ; Actor 2
         dw $4420        ; Actor 3
         dw $5020        ; Actor 4
         dw $5C20        ; Actor 5
         dw $6820        ; Actor 6
         dw $7420        ; Actor 7
         dw $8020        ; Actor 8
         dw $8C20        ; Actor 9
         dw $9820        ; Actor 10
         dw $A420        ; Actor 11
         dw $B020        ; Actor 12
         dw $BC10        ; End

; Cursor positions for Colosseum matchup menu
C3B337:  dw $B010        ; Member 1
         dw $B048        ; Member 2
         dw $B080        ; Member 3
         dw $B0B8        ; Member 4

; Cursor positions for main shop menu
C3B89A:  dw $3408        ; BUY
         dw $3430        ; SELL
         dw $3460        ; EXIT

; Cursor positions for Buy menu
C3B8B4:  dw $3400        ; Item 1
         dw $4000        ; Item 2
         dw $4C00        ; Item 3
         dw $5800        ; Item 4
         dw $6400        ; Item 5
         dw $7000        ; Item 6
         dw $7C00        ; Item 7
         dw $8800        ; Item 8

; ==============================[ Object data ]================================

; OAM for blank sprite
C30895:  db $00          ; Tiles: 0

; Animation table for main cursor
C3088D:  dw C30890       ; Sprite 1
         db $FE          ; Freeze

; OAM for hand cursor
C30890:  db $01          ; Tiles: 1
         dw $0080        ; 16x16, X+0, Y+0
         dw $3E00        ; Tile 0, pal 7, prio 3

; Animation table for blinking cursor
C30896:  dw C30890       ; Show cursor
         db $02          ; Frames: 2
         dw C30895       ; Hide cursor
         db $02          ; Frames: 2
         dw C30890       ; Bogus...
         db $FF          ; Loop

; Pointers to scrollbar animation tables
C309DB:  dw C309EC       ; Flashing up
         dw C309F5       ; Flashing down
         dw C309E3       ; Flashing both ways

; Animation table for scrollbar flashing both ways
C309E3:  dw C309FE       ; Flash neither
         db $10          ; Frames: 16
         dw C30A07       ; Flash both
         db $10          ; Frames: 16
         dw C309FE       ; Bogus...
         db $FF          ; Loop

; Animation table for scrollbar pointing up
C309EC:  dw C309FE       ; Flash neither
         db $10          ; Frames: 16
         dw C30A10       ; Flash highest
         db $10          ; Frames: 16
         dw C309FE       ; Bogus...
         db $FF          ; Loop

; Animation table for scrollbar pointing down
C309F5:  dw C309FE       ; Flash neither
         db $10          ; Frames: 16
         dw C30A19       ; Flash lowest
         db $10          ; Frames: 16
         dw C309FE       ; Bogus...
         db $FF          ; Loop

; OAM for non-flashing scrollbar
C309FE:  db $02          ; Tiles: 2
         dw $0000,$3E02  ; ^: White
         dw $0800,$BE02  ; v: White

; OAM for scrollbar flashing both ways
C30A07:  db $02          ; Tiles: 2
         dw $0000,$3E12  ; ^: Black
         dw $0800,$BE12  ; v: Black

; OAM for scrollbar pointing up
C30A10:  db $02          ; Tiles: 2
         dw $0000,$3E12  ; ^: Black
         dw $0800,$BE02  ; v: White

; OAM for scrollbar pointing down
C30A19:  db $02          ; Tiles: 2
         dw $0000,$3E02  ; ^: White
         dw $0800,$BE12  ; v: Black

; Pointers to portrait animation tables
C30AE9:  dw C30B8C       ; Portrait A
         dw C30BC4       ; Portrait B
         dw C30BFC       ; Portrait C
         dw C30C34       ; Portrait D

; Animation table for portrait A
C30B8C:  dw C30B8F       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait A
C30B8F:  db $0D          ; Tiles: 13
         dw $0080,$2060  ; Tile 1
         dw $0090,$2062  ; Tile 2
         dw $1080,$2064  ; Tile 3
         dw $1090,$2066  ; Tile 4
         dw $0020,$2068  ; Tile 5
         dw $0820,$2069  ; Tile 6
         dw $1020,$206A  ; Tile 7
         dw $1820,$206B  ; Tile 8
         dw $2020,$206C  ; Tile 9
         dw $2000,$206D  ; Tile 10
         dw $2008,$206E  ; Tile 11
         dw $2010,$206F  ; Tile 12
         dw $2018,$2078  ; Tile 13

; Animation table for portrait B
C30BC4:  dw C30BC7       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait B
C30BC7:  db $0D          ; Tiles: 13
         dw $0080,$2280  ; Tile 1
         dw $0090,$2282  ; Tile 2
         dw $1080,$2284  ; Tile 3
         dw $1090,$2286  ; Tile 4
         dw $0020,$2288  ; Tile 5
         dw $0820,$2289  ; Tile 6
         dw $1020,$228A  ; Tile 7
         dw $1820,$228B  ; Tile 8
         dw $2020,$228C  ; Tile 9
         dw $2000,$228D  ; Tile 10
         dw $2008,$228E  ; Tile 11
         dw $2010,$228F  ; Tile 12
         dw $2018,$2298  ; Tile 13

; Animation table for portrait C
C30BFC:  dw C30BFF       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait C
C30BFF:  db $0D          ; Tiles: 13
         dw $0080,$24A0  ; Tile 1
         dw $0090,$24A2  ; Tile 2
         dw $1080,$24A4  ; Tile 3
         dw $1090,$24A6  ; Tile 4
         dw $0020,$24A8  ; Tile 5
         dw $0820,$24A9  ; Tile 6
         dw $1020,$24AA  ; Tile 7
         dw $1820,$24AB  ; Tile 8
         dw $2020,$24AC  ; Tile 9
         dw $2000,$24AD  ; Tile 10
         dw $2008,$24AE  ; Tile 11
         dw $2010,$24AF  ; Tile 12
         dw $2018,$24B8  ; Tile 13

; Animation table for portrait D
C30C34:  dw C30C37       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait D
C30C37:  db $0D          ; Tiles: 13
         dw $0080,$26C0  ; Tile 1
         dw $0090,$26C2  ; Tile 2
         dw $1080,$26C4  ; Tile 3
         dw $1090,$26C6  ; Tile 4
         dw $0020,$26C8  ; Tile 5
         dw $0820,$26C9  ; Tile 6
         dw $1020,$26CA  ; Tile 7
         dw $1820,$26CB  ; Tile 8
         dw $2020,$26CC  ; Tile 9
         dw $2000,$26CD  ; Tile 10
         dw $2008,$26CE  ; Tile 11
         dw $2010,$26CF  ; Tile 12
         dw $2018,$26D8  ; Tile 13

; X positions for actors on save files
C3197F:  dw $6850,$9880  ; File 1
         dw $6850,$9880  ; File 2
         dw $6850,$9880  ; File 3

; Y positions for actors on save files
C3198B:  dw $4040,$4040  ; File 1
         dw $7878,$7878  ; File 2
         dw $B0B0,$B0B0  ; File 3

; Actors' OAM complements when on "New Game"
C31997:  dw $0202,$0202  ; File 1: Grayscale
         dw $0202,$0202  ; File 2: Grayscale
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 1
C319A3:  dw $0000,$0000  ; File 1: None
         dw $0202,$0202  ; File 2: Grayscale
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 2
C319AF:  dw $0202,$0202  ; File 1: Grayscale
         dw $0000,$0000  ; File 2: None
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 3
C319BB:  dw $0202,$0202  ; File 1: Grayscale
         dw $0202,$0202  ; File 2: Grayscale
         dw $0000,$0000  ; File 3: None

; Pointers for Config's large arrows
C339C7:  dw C339CB       ; Downward arrow
         dw C339D4       ; Upward arrow

; Animation table for large downward arrow
C339CB:  dw C30895       ; Hide arrow
         db $10          ; Frames: 16
         dw C339DD       ; Show arrow
         db $10          ; Frames: 16
         dw C30895       ; Bogus...
         db $FF          ; Loop

; Animation table for large upward arrow
C339D4:  dw C30895       ; Hide arrow
         db $10          ; Frames: 16
         dw C3B461       ; Show arrow
         db $10          ; Frames: 16
         dw C30895       ; Bogus...
         db $FF          ; Loop

; OAM for large downward arrow
C339DD:  db $01          ; Tiles: 1
         dw $B080        ; 16x16, X+0, Y+176
         dw $3E03        ; Tile 3, pal 7, prio 3

; OAM for small white arrow in actor naming menu
C3B448:  db $01          ; Tiles: 1
         dw $0009        ; 8x8, X+9, Y+0
         dw $3E02        ; Tile 2, pal 7, prio 3

; OAM for small black arrow in actor naming menu
C3B44D:  db $01          ; Tiles: 1
         dw $0009        ; 8x8, X+9, Y+0
         dw $3E12        ; Tile 18, pal 7, prio 3

; Animation table for small arrow in actor naming menu
C3B452:  dw C3B448       ; White arrow
         db $02          ; Frames: 2
         dw C3B44D       ; Black arrow
         db $02          ; Frames: 2
         dw C3B448       ; Bogus...
         db $FF          ; Loop

; OAM for large downward arrow in SwdTech naming menu (SFC)
C3B45C:  db $01          ; Tiles: 1
         dw $8280        ; 16x16, X+0, Y+130
         dw $3E03        ; Tile 3, pal 7, prio 3

; OAM for large upward arrow
C3B461:  db $01          ; Tiles: 1
         dw $0080        ; 16x16, X+0, Y+0
         dw $BE03        ; Tile 3, pal 7, prio 3, V-Flip

; Arrow's X positions in actor naming menu
C368DD:  db $78          ; Letter 1
         db $80          ; Letter 2
         db $88          ; Letter 3
         db $90          ; Letter 4
         db $98          ; Letter 5
         db $A0          ; Letter 6

; X positions for candidates in Lineup menu
C376CA:  db $18          ; Slot 1
         db $34          ; Slot 2
         db $50          ; Slot 3
         db $6C          ; Slot 4
         db $88          ; Slot 5
         db $A4          ; Slot 6
         db $C0          ; Slot 7
         db $DC          ; Slot 8
         db $18          ; Slot 9
         db $34          ; Slot 10
         db $50          ; Slot 11
         db $6C          ; Slot 12
         db $88          ; Slot 13
         db $A4          ; Slot 14
         db $C0          ; Slot 15
         db $DC          ; Slot 16

; Y positions for candidates in Lineup menu
C376DA:  db $5C          ; Slot 1
         db $5C          ; Slot 2
         db $5C          ; Slot 3
         db $5C          ; Slot 4
         db $5C          ; Slot 5
         db $5C          ; Slot 6
         db $5C          ; Slot 7
         db $5C          ; Slot 8
         db $78          ; Slot 9
         db $78          ; Slot 10
         db $78          ; Slot 11
         db $78          ; Slot 12
         db $78          ; Slot 13
         db $78          ; Slot 14
         db $78          ; Slot 15
         db $78          ; Slot 16

; X positions for party members in Lineup menu
C378E3:  db $18          ; Party 1 (NW)
         db $18          ; Party 1 (SW)
         db $38          ; Party 1 (NE)
         db $38          ; Party 1 (SE)
         db $68          ; Party 2 (NW)
         db $68          ; Party 2 (SW)
         db $88          ; Party 2 (NE)
         db $88          ; Party 2 (SE)
         db $B8          ; Party 3 (NW)
         db $B8          ; Party 3 (SW)
         db $D8          ; Party 3 (NE)
         db $D8          ; Party 3 (SE)

; Y positions for party members in Lineup menu
C378E7:  db $9C          ; NW
         db $B8          ; SW
         db $9C          ; NE
         db $B8          ; SE

; X positions for shop actors
C3C0ED:  db $18          ; Actor 1
         db $38          ; Actor 2
         db $58          ; Actor 3
         db $78          ; Actor 4
         db $98          ; Actor 5
         db $B8          ; Actor 6
         db $D8          ; Actor 7
         db $18          ; Actor 8
         db $38          ; Actor 9
         db $58          ; Actor 10
         db $78          ; Actor 11
         db $98          ; Actor 12
         db $B8          ; Actor 13
         db $D8          ; Actor 14

; Y positions for shop actors
C3C0FB:  db $9C          ; Actor 1
         db $9C          ; Actor 2
         db $9C          ; Actor 3
         db $9C          ; Actor 4
         db $9C          ; Actor 5
         db $9C          ; Actor 6
         db $9C          ; Actor 7
         db $B8          ; Actor 8
         db $B8          ; Actor 9
         db $B8          ; Actor 10
         db $B8          ; Actor 11
         db $B8          ; Actor 12
         db $B8          ; Actor 13
         db $B8          ; Actor 14

; =============================[ Window layouts ]==============================

; Save and Load menus
C3189C:  dw $58CB,$021C  ; 30x4 at $58CB (Top window)
C318A0:  dw $59CB,$051C  ; 30x7 at $59CB (File A)
C318A4:  dw $5B8B,$051C  ; 30x7 at $5B8B (File B)
C318A8:  dw $5D4B,$051C  ; 30x7 at $5D4B (File C)

; Main menu
C331BB:  dw $60B9,$0207  ; 09x04 at $60B9 (Order; L part)
         dw $5885,$0201  ; 03x04 at $5885 (Order; R part)
C331C7:  dw $588B,$181C  ; 30x26 at $588B (Party)
         dw $58B7,$0D06  ; 08x15 at $58B7 (Options)
         db $00          ; End

; Main menu and save file submenus
C331BF:  dw $5C77,$0206  ; 08x04 at $5C77 (Time)
         dw $5D75,$0507  ; 09x07 at $5D75 (Steps)
         db $00          ; End

; Save file submenus
C331CB:  dw $58B5,$0A07  ; 09x12 at $58B5 (Yes/No)

; Config menu
C339E2:  dw $590B,$161C  ; 30x24 at $590B (Main)
         dw $58B7,$0206  ; 08x04 at $58B7 (Title)
         db $00          ; End

; Cmd.Set menu
C34490:  dw $591F,$0412  ; 20x06 at $591F (Command set A)
         dw $5A9F,$0412  ; 20x06 at $5A9F (Command set B)
         dw $5C1F,$0412  ; 20x06 at $5C1F (Command set C)
         dw $5D9F,$0412  ; 20x06 at $5D9F (Command set D)
         dw $590B,$0408  ; 10x06 at $590B (Member name A)
         dw $5A8B,$0408  ; 10x06 at $5A8B (Member name B)
         dw $5C0B,$0408  ; 10x06 at $5C0B (Member name C)
         dw $5D8B,$0408  ; 10x06 at $5D8B (Member name D)
         dw $588B,$0108  ; 10x03 at $588B (Arrange)
         db $00          ; End

; Controller menu
C348F3:  dw $5B0B,$0B1C  ; 30x13 at $5B0B

; Main Skills menu
C34D98:  dw $59CB,$051C  ; 30x07 at $59CB (Stats)
         dw $588B,$031C  ; 30x05 at $588B (Top)
         dw $5B8B,$0C1C  ; 30x14 at $5B8B (Bottom)
         dw $588B,$0407  ; 09x06 at $588B (Upper submenus)
         dw $5A0B,$0A07  ; 09x12 at $5A0B (Lower submenus)

; Skills submenus
         dw $61CB,$051C  ; 30x07 at $61CB (Stats)
         dw $638B,$0C1C  ; 30x14 at $638B (List)
         dw $608B,$031C  ; 30x05 at $608B (Description)
         dw $6175,$0107  ; 09x03 at $6175 (Title)
         db $00          ; End

; Spell usage menu
C3583F:  dw $589D,$1813  ; 21x26 at $589D (Party)
         dw $588B,$0207  ; 09x04 at $588B (Spell)
         dw $598B,$0307  ; 09x05 at $598B (MP cost)
         db $00          ; End

; Status menu
C35F79:  dw $588B,$181C  ; 30x26 at $588B (Main)
         dw $588B,$0106  ; 08x03 at $588B (Title)
         dw $5AEB,$0609  ; 11x08 at $5AEB (Commands)
         db $00          ; End

; Gogo's list of available commands
C35F85:  dw $58C7,$1200  ; 02x20 at $58C7 (L part)
C35F89:  dw $6087,$1207  ; 09x20 at $6087 (R part)

; Actor naming menu
C36761:  dw $5A57,$1116  ; 24x19 at $5A57 (Options)
         dw $599B,$0212  ; 20x04 at $599B (Name)
         dw $588B,$0505  ; 07x07 at $588B (Portrait)
         dw $5899,$0214  ; 22x04 at $5899 ("Please...")
         db $00          ; End

; Lineup menu
C37598:  dw $588B,$0206  ; 08x04 at $588B (Title)
         dw $5CCB,$071C  ; 30x09 at $5CCB (Parties)
         dw $598B,$051C  ; 30x07 at $598B (Stats)
         dw $5B0B,$061C  ; 30x08 at $5B0B (Candidates)
         dw $589B,$0214  ; 22x04 at $589B (Messages)
         dw $5D0B,$0608  ; 10x08 at $5D0B (Party 1)
         db $00          ; End

; Party boxes for Lineup menu
C375B0:  dw $5D33,$0608  ; 10x08 at $5D33 (Party 3)
C375B4:  dw $5D1F,$0608  ; 10x08 at $5D1F (Party 2)
         db $00          ; End

; Item menu and gear data menu
C37E13:  dw $60AD,$180D  ; 15x26 at $60AD (Gear stats; L part)
         dw $5885,$1801  ; 03x26 at $5885 (Gear stats; R part)
         dw $5ACB,$0F1C  ; 30x17 at $5ACB (Main)
         dw $598B,$031C  ; 30x05 at $598B (Description)
         dw $588B,$0204  ; 06x04 at $588B (Title)
         dw $5897,$0216  ; 24x04 at $5897 (Options)
         db $00          ; End

; Item usage menu
C38A3B:  dw $589D,$1813  ; 21x26 at $589D (Party)
         dw $588B,$020D  ; 15x04 at $588B (Item)
         dw $598B,$0307  ; 09x05 at $598B (Quantity)
         db $00          ; End

; Party gear overview
C3902E:  dw $588B,$181C  ; 30x26 at $588B

; Equip and Relic menus
C3947F:  dw $5B4B,$0D1C  ; 30x15 at $5B4B (Stats w/o title)
         dw $590B,$071C  ; 30x09 at $590B (Gear w/o title)
         dw $588B,$021C  ; 30x04 at $588B (Options)
         dw $634B,$0D1C  ; 30x15 at $634B (Stats w/ title)
         dw $610B,$071C  ; 30x09 at $610B (Gear w/ title)
         dw $60B7,$0206  ; 08x04 at $60B7 (Title)
         db $00          ; End

; Final battle lineup
C3AB49:  dw $588B,$181C  ; 30x26 at $588B

; Colosseum item menu
C3AD8A:  dw $58A1,$0211  ; 19x04 at $58A1 ("Select...")
         dw $588B,$0209  ; 11x04 at $588B (Title)
         dw $598B,$031C  ; 30x05 at $598B (Description)
         dw $5ACB,$0F1C  ; 30x17 at $5ACB (Items)
         db $00          ; End

; Colosseum matchup menu
C3B33F:  dw $588B,$020D  ; 15x4 at $588B (Prize)
         dw $58A9,$020D  ; 15x4 at $58A9 (Bet)
         dw $5CCB,$071C  ; 30x9 at $5CCB (Party)
         db $00          ; End

; Sell menu and main shop menu
C3BC1B:  dw $588B,$0207  ; 09x04 at $588B (Title)
         dw $589D,$0213  ; 21x04 at $589D (Dialogue)
         dw $598B,$0210  ; 18x04 at $598B (Options)
         dw $59AF,$020A  ; 12x04 at $59AF (GP)
         dw $5A8B,$101C  ; 30x18 at $5A8B (Items)

; Buy menu
         dw $608B,$0207  ; 09x04 at $608B (Title)
         dw $609D,$0213  ; 21x04 at $609D (Dialogue)
         dw $618B,$0C1C  ; 30x14 at $618B (Items)
         dw $650B,$061C  ; 30x08 at $650B (Actors)

; Shop order menus
         dw $688B,$0207  ; 09x04 at $688B (Title)
         dw $689D,$0213  ; 21x04 at $689D (Dialogue)
         dw $698B,$0711  ; 19x09 at $698B (Item)
         dw $6BCB,$031C  ; 30x05 at $6BCB (Description)
         dw $6D0B,$061C  ; 30x08 at $6D0B (Actors)
         dw $69B1,$0709  ; 11x09 at $69B1 (Amounts)
         db $00          ; End

; ==========================[ Text shifting tables ]===========================

; Text shifting table for save file confirmation, Colosseum matchup
C318F0:  db $20,$00,$00  ; 32 lines, shift by 0 px
         db $0C,$04,$00  ; 12 lines, shift by 4 px
         db $0C,$08,$00  ; 12 lines, shift by 8 px
         db $08,$C8,$FF  ; 8 lines, shift by -38 px
         db $50,$00,$00  ; 80 lines, shift by 0 px
         db $58,$00,$00  ; 88 lines, shift by 0 px
         db $00          ; End

; Text shifting table for main menu
C336C2:  db $0F,$00,$00  ; Nothing
         db $0F,$03,$00  ; Item
         db $0F,$04,$00  ; Skills
         db $0F,$05,$00  ; Equip
         db $0F,$06,$00  ; Relic
         db $0F,$07,$00  ; Status
         db $0F,$08,$00  ; Config
         db $0F,$09,$00  ; Save
         db $07,$08,$00  ; Nothing
         db $08,$00,$00  ; Nothing
         db $08,$00,$00  ; Time
         db $18,$00,$00  ; The rest
         db $00          ; End

; Text shifting table for Cmd.Set menu
C3468E:  db $1F,$00,$00  ; Arrange
         db $0C,$04,$00  ; Row 1
         db $0C,$08,$00  ; Row 2
         db $24,$0C,$00  ; Row 3, row 4
         db $0C,$10,$00  ; Row 5
         db $24,$14,$00  ; Row 6, row 7
         db $0C,$18,$00  ; Row 8
         db $24,$1C,$00  ; Row 9, row 10
         db $0C,$20,$00  ; Row 11
         db $24,$24,$00  ; Row 12
         db $00          ; End

; BG3 V-Shift table for skill menus
C34E26:  db $4F,$02,$00  ; SwdTech and above
         db $40,$02,$00  ; Blitz and below
         db $00          ; End

; BG1 H-Shift table for skill menus (merges tilemaps)
C34E72:  db $27,$00,$01  ; Nothing
         db $48,$00,$01  ; Member stats
         db $60,$00,$00  ; Spells, etc.
         db $1E,$00,$01  ; Nothing
         db $00          ; End

; BG1 V-Shift table for skill menus (condenses text)
C34E7F:  db $3F,$00,$00  ; LV
         db $0C,$04,$00  ; HP
         db $0C,$08,$00  ; MP
         db $0A,$0C,$00  ; Nothing
         db $01,$0C,$00  ; Nothing
         db $0D,$08,$00  ; Nothing
         db $04,$94,$FF  ; Ability row A
         db $04,$94,$FF  ; Ability row B
         db $04,$94,$FF  ; Ability row C
         db $04,$98,$FF  ; Ability row D
         db $04,$98,$FF  ; Ability row E
         db $04,$98,$FF  ; Ability row F
         db $04,$9C,$FF  ; Ability row G
         db $04,$9C,$FF  ; Ability row H
         db $04,$9C,$FF  ; Ability row I
         db $04,$A0,$FF  ; Ability row J
         db $04,$A0,$FF  ; Ability row K
         db $04,$A0,$FF  ; Ability row L
         db $04,$A4,$FF  ; Ability row M
         db $04,$A4,$FF  ; Ability row N
         db $04,$A4,$FF  ; Ability row O
         db $04,$A8,$FF  ; Ability row P
         db $04,$A8,$FF  ; Ability row Q
         db $04,$A8,$FF  ; Ability row R
         db $04,$AC,$FF  ; Ability row S
         db $04,$AC,$FF  ; Ability row T
         db $04,$AC,$FF  ; Ability row U
         db $04,$B0,$FF  ; Ability row V
         db $04,$B0,$FF  ; Ability row W
         db $04,$B0,$FF  ; Ability row X
         db $1E,$20,$FF  ; Ability row Y
         db $00          ; End

; Text shifting table for Status menu
C3622A:  db $27,$00,$00  ; Status
         db $0C,$04,$00  ; Cmd choice A
         db $0C,$08,$00  ; Cmd choice B
         db $0C,$0C,$00  ; Cmd choice C
         db $0C,$10,$00  ; Cmd choice D
         db $0C,$14,$00  ; Command A
         db $0C,$18,$00  ; Command B
         db $0C,$1C,$00  ; Command C
         db $0C,$20,$00  ; Command D
         db $0C,$24,$00  ; Needed exp.
         db $0C,$28,$00  ; Bat.Pwr
         db $0C,$2C,$00  ; Defense
         db $0C,$30,$00  ; Evade
         db $0C,$34,$00  ; Mag.Def
         db $0C,$38,$00  ; MBlock
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; BG1 H-Shift table for actor naming menu (merges tilemaps)
C36889:  db $47,$00,$01  ; Title, name
         db $50,$00,$00  ; Upper chars
         db $50,$00,$00  ; Lower chars
         db $10,$00,$01  ; Blank area
         db $00          ; End

; BG1 V-Shift table for actor naming menu (condenses text)
C36896:  db $47,$00,$00  ; Title, name
         db $50,$D0,$FF  ; Upper chars
         db $50,$D0,$FF  ; Lower chars
         db $10,$00,$00  ; Blank area
         db $00          ; End

; Text shifting table for Lineup menu
C375E4:  db $20,$02,$00  ; Title
         db $08,$00,$00  ; Nothing
         db $0B,$04,$00  ; Nothing
         db $0C,$08,$00  ; Level
         db $0C,$0C,$00  ; HP
         db $0C,$10,$00  ; MP
         db $00          ; End

; Shift amount for 1st of every 3 rows of list scrolling down
C3815F:  dw $0008        ; Frame 3: +8 px down
         dw $0004        ; Frame 2: +4 px down
         dw $0004        ; Frame 1: +4 px down

; Shift amount for 1st of every 3 rows of list scrolling up
         dw $FFFC        ; Frame 3: +4 px up
         dw $FFFC        ; Frame 2: +4 px up
         dw $FFF8        ; Frame 1: +8 px up

; Shift amount for 2nd of every 3 rows of list scrolling down
C3816B:  dw $0004        ; Frame 3: +4 px down
         dw $0008        ; Frame 2: +8 px down
         dw $0004        ; Frame 1: +4 px down

; Shift amount for 2nd of every 3 rows of list scrolling up
         dw $FFFC        ; Frame 3: +4 px up
         dw $FFF8        ; Frame 2: +8 px up
         dw $FFFC        ; Frame 1: +4 px up

; Shift amount for every 3rd row of list scrolling down
C38177:  dw $0004        ; Frame 3: +4 px down
         dw $0004        ; Frame 2: +4 px down
         dw $0008        ; Frame 1: +8 px down

; Shift amount for every 3rd row of list scrolling up
         dw $FFF8        ; Frame 3: +8 px up
         dw $FFFC        ; Frame 2: +4 px up
         dw $FFFC        ; Frame 1: +4 px up

; BG1 H-Shift table for inventory-style menus
C37EDA:  db $28,$00,$01  ; Nothing
         db $2F,$00,$01  ; Nothing
         db $78,$00,$00  ; Items
         db $1E,$00,$01  ; Nothing
         db $00          ; End

; BG1 V-Shift table for inventory-style menus
C37EE7:  db $27,$80,$00  ; Nothing?
         db $08,$00,$00  ; Nothing?
         db $0C,$04,$00  ; Nothing?
         db $0C,$08,$00  ; Nothing?
         db $08,$80,$00  ; Nothing?
         db $08,$00,$00  ; Nothing?
         db $04,$AC,$FF  ; Item row 1
         db $04,$AC,$FF  ; Item row 2
         db $04,$AC,$FF  ; Item row 3
         db $04,$B0,$FF  ; Item row 4
         db $04,$B0,$FF  ; Item row 5
         db $04,$B0,$FF  ; Item row 6
         db $04,$B4,$FF  ; Item row 7
         db $04,$B4,$FF  ; Item row 8
         db $04,$B4,$FF  ; Item row 9
         db $04,$B8,$FF  ; Item row 10
         db $04,$B8,$FF  ; Item row 11
         db $04,$B8,$FF  ; Item row 12
         db $04,$BC,$FF  ; Item row 13
         db $04,$BC,$FF  ; Item row 14
         db $04,$BC,$FF  ; Item row 15
         db $04,$C0,$FF  ; Item row 16
         db $04,$C0,$FF  ; Item row 17
         db $04,$C0,$FF  ; Item row 18
         db $04,$C4,$FF  ; Item row 19
         db $04,$C4,$FF  ; Item row 20
         db $04,$C4,$FF  ; Item row 21
         db $04,$C8,$FF  ; Item row 22
         db $04,$C8,$FF  ; Item row 23
         db $04,$C8,$FF  ; Item row 24
         db $04,$CC,$FF  ; Item row 25
         db $04,$CC,$FF  ; Item row 26
         db $04,$CC,$FF  ; Item row 27
         db $04,$D0,$FF  ; Item row 28
         db $04,$D0,$FF  ; Item row 29
         db $04,$D0,$FF  ; Item row 30
         db $1E,$00,$00  ; Nothing
         db $00          ; End

; BG3 V-Shift table for Item and Colosseum menus
C37F57:  db $2F,$00,$00  ; Title
         db $0C,$04,$00  ; Desc row 1
         db $0C,$08,$00  ; Desc row 2
         db $0C,$0C,$00  ; 2-hand
         db $0C,$10,$00  ; 50% Dmg
         db $0C,$14,$00  ; Vigor
         db $0C,$18,$00  ; Speed
         db $0C,$1C,$00  ; Stamina
         db $0C,$20,$00  ; Mag.Pwr
         db $0C,$24,$00  ; Bat.Pwr
         db $0C,$28,$00  ; Defense
         db $0C,$2C,$00  ; Evade
         db $0C,$30,$00  ; Mag.Def
         db $0C,$34,$00  ; MBlock
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; BG1 H-Shift table for gear list browsing
C39564:  db $27,$00,$01  ; Nothing?
         db $3C,$00,$01  ; Nothing?
         db $6C,$00,$00  ; Item list
         db $1E,$00,$01  ; Nothing?
         db $00          ; End

; BG1 V-Shift table for gear list browsing
C39571:  db $3F,$00,$00  ; Nothing?
         db $0C,$04,$00  ; Nothing?
         db $0C,$08,$00  ; Nothing?
         db $0A,$0C,$00  ; Nothing?
         db $01,$0C,$00  ; Nothing?
         db $01,$0C,$00  ; Nothing?
         db $04,$A0,$FF  ; Item row 1
         db $04,$A0,$FF  ; Item row 2
         db $04,$A0,$FF  ; Item row 3
         db $04,$A4,$FF  ; Item row 4
         db $04,$A4,$FF  ; Item row 5
         db $04,$A4,$FF  ; Item row 6
         db $04,$A8,$FF  ; Item row 7
         db $04,$A8,$FF  ; Item row 8
         db $04,$A8,$FF  ; Item row 9
         db $04,$AC,$FF  ; Item row 10
         db $04,$AC,$FF  ; Item row 11
         db $04,$AC,$FF  ; Item row 12
         db $04,$B0,$FF  ; Item row 13
         db $04,$B0,$FF  ; Item row 14
         db $04,$B0,$FF  ; Item row 15
         db $04,$B4,$FF  ; Item row 16
         db $04,$B4,$FF  ; Item row 17
         db $04,$B4,$FF  ; Item row 18
         db $04,$B8,$FF  ; Item row 19
         db $04,$B8,$FF  ; Item row 20
         db $04,$B8,$FF  ; Item row 21
         db $04,$BC,$FF  ; Item row 22
         db $04,$BC,$FF  ; Item row 23
         db $04,$BC,$FF  ; Item row 24
         db $04,$C0,$FF  ; Item row 25
         db $04,$C0,$FF  ; Item row 26
         db $04,$C0,$FF  ; Item row 27
         db $1E,$10,$00  ; Nothing?
         db $00          ; End

; V-Shift table for gear menus and final battle lineup
C395D8:  db $0F,$00,$00  ; Nothing
         db $0C,$04,$00  ; Options, title
         db $0C,$08,$00  ; Reequip mode
         db $0C,$0C,$00  ; R-Hand
         db $0C,$10,$00  ; L-Hand
         db $0C,$14,$00  ; Head, Relic 1
         db $0C,$18,$00  ; Body, Relic 2
         db $0C,$1C,$00  ; Member 2's armor
         db $0C,$20,$00  ; Vigor
         db $0C,$24,$00  ; Speed
         db $0C,$28,$00  ; Stamina
         db $0C,$2C,$00  ; Mag.Pwr
         db $0C,$30,$00  ; Bat.Pwr
         db $0C,$34,$00  ; Defense
         db $0C,$38,$00  ; Evade
         db $0C,$3C,$00  ; Mag.Def
         db $0C,$40,$00  ; MBlock
         db $00          ; End

; BG3 text shifting table for shop
C3C037:  db $2F,$04,$00  ; Title
         db $0C,$04,$00  ; Item 1
         db $0C,$08,$00  ; Item 2
         db $0C,$0C,$00  ; Item 3
         db $0C,$10,$00  ; Item 4
         db $0C,$14,$00  ; Item 5
         db $0C,$18,$00  ; Item 6
         db $0C,$1C,$00  ; Item 7
         db $0C,$20,$00  ; Item 8
         db $0C,$24,$00  ; Nothing
         db $0C,$28,$00  ; Nothing
         db $0C,$2C,$00  ; Nothing
         db $0C,$30,$00  ; Nothing
         db $0C,$34,$00  ; Nothing
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; ============================[ Tilemap pointers ]=============================

; Tilemap pointers for stats of member 1
C3332D:  dw $39A7        ; Level
         dw $39E3        ; HP
         dw $39ED        ; Max HP
         dw $3A23        ; MP
         dw $3A2D        ; Max MP

; Tilemap pointers for stats of member 2
C33379:  dw $3B27        ; Level
         dw $3B63        ; HP
         dw $3B6D        ; Max HP
         dw $3BA3        ; MP
         dw $3BAD        ; Max MP

; Tilemap pointers for stats of member 3
C333C5:  dw $3CA7        ; Level
         dw $3CE3        ; HP
         dw $3CED        ; Max HP
         dw $3D23        ; MP
         dw $3D2D        ; Max MP

; Tilemap pointers for stats of member 4
C33411:  dw $3E27        ; Level
         dw $3E63        ; HP
         dw $3E6D        ; Max HP
         dw $3EA3        ; MP
         dw $3EAD        ; Max MP

; Tilemap pointers for Bat.Speed values
C33BE6:  dw $3A25        ; 1
         dw $3A29        ; 2
         dw $3A2D        ; 3
         dw $3A31        ; 4
         dw $3A35        ; 5
         dw $3A39        ; 6

; Tilemap pointers for Msg.Speed values
C33C27:  dw $3AA5        ; 1
         dw $3AA9        ; 2
         dw $3AAD        ; 3
         dw $3AB1        ; 4
         dw $3AB5        ; 5
         dw $3AB9        ; 6

; Tilemap pointers for Mag.Order values
C3402F:  dw $41A5        ; 1
         dw $41A9        ; 2
         dw $41AD        ; 3
         dw $41B1        ; 4
         dw $41B5        ; 5
         dw $41B9        ; 6

; Tilemap pointers for Mag.Order strings
C340CC:  dw $4329        ; Spell type C
         dw $42A9        ; Spell type B
         dw $4229        ; Spell type A

; Tilemap pointers for wallpaper values
C34123:  dw $43A5        ; 1
         dw $43A9        ; 2
         dw $43AD        ; 3
         dw $43B1        ; 4
         dw $43B5        ; 5
         dw $43B9        ; 6
         dw $43BD        ; 7
         dw $43C1        ; 8

; Tilemap pointers for stats in Skills menu
C34F12:  dw $4237        ; Level
         dw $42B3        ; HP
         dw $42BD        ; Max HP
         dw $4333        ; MP
         dw $433D        ; Max MP

; Tilemap pointers for stats in Status menu
C36096:  dw $3A27        ; Level
         dw $3A63        ; HP
         dw $3A6D        ; Max HP
         dw $3AA3        ; MP
         dw $3AAD        ; Max MP

; Tilemap pointers for stats in Lineup menu
C379E6:  dw $3A77        ; LV
         dw $3AF3        ; HP
         dw $3AFD        ; Max HP
         dw $3B73        ; MP
         dw $3B7D        ; Max MP

; Text positions for gear data menu
C38653:  dw $7E0F        ; Actor name 1
         dw $7E23        ; Actor name 2
         dw $7E37        ; Actor name 3
         dw $7E8F        ; Actor name 4
         dw $7EA3        ; Actor name 5
         dw $7EB7        ; Actor name 6
         dw $7F0F        ; Actor name 7
         dw $7F23        ; Actor name 8
         dw $7F37        ; Actor name 9
         dw $7F8F        ; Actor name 10
         dw $7FA3        ; Actor name 11
         dw $7FB7        ; Actor name 12
         dw $800F        ; Actor name 13
         dw $8023        ; Actor name 14
;        dw $8037        ; Actor name 15 (unused)

; X positions for party gear overview
C38FD5:  db $02          ; R-Hand
         db $11          ; L-Hand
         db $02          ; Head
         db $11          ; Body
         db $02          ; Relic 1
         db $11          ; Relic 2

; Relative Y positions for party gear overview
C38FDB:  db $01          ; R-Hand
         db $01          ; L-Hand
         db $03          ; Head
         db $03          ; Body
         db $05          ; Relic 1
         db $05          ; Relic 2

; Tilemap pointers for Buy menu
C3B9FC:  dw $7A0D        ; Item 1
         dw $7A8D        ; Item 2
         dw $7B0D        ; Item 3
         dw $7B8D        ; Item 4
         dw $7C0D        ; Item 5
         dw $7C8D        ; Item 6
         dw $7D0D        ; Item 7
         dw $7D8D        ; Item 8

; ==================================[ Text ]===================================

; Positioned text for save menus
C31A24:  dw $7A4F : db "Empty",$00
C31A2C:  dw $7C0F : db "Empty",$00
C31A34:  dw $7DCF : db "Empty",$00
C31A3C:  dw $7ACF : db "Time",$00
C31A43:  dw $7C8F : db "Time",$00
C31A4A:  dw $7E4F : db "Time",$00
C31A51:  dw $7B11 : db ":",$00
C31A55:  dw $7CD1 : db ":",$00
C31A59:  dw $7E91 : db ":",$00
C31A5D:  dw $7A7B : db "LV",$00
C31A62:  dw $7C3B : db "LV",$00
C31A67:  dw $7DFB : db "LV",$00
C31A6C:  dw $7AFB : db "/",$00
C31A70:  dw $7CBB : db "/",$00
C31A74:  dw $7E7B : db "/",$00
C31A78:  dw $7967 : db "Save",$00
C31A7F:  dw $7963 : db "New Game",$00

; Ordered list of item icons for Arrange command
C326F5:  db $FF          ; No icon
         db $D8          ; Dirk
         db $D9          ; Sword
         db $DA          ; Lance
         db $DB          ; Knife
         db $DC          ; Rod
         db $DD          ; Brush
         db $DE          ; Stars
         db $DF          ; Special
         db $E0          ; Gambler
         db $E1          ; Claw
         db $E2          ; Shield
         db $E3          ; Helmet
         db $E4          ; Armor
         db $E5          ; Tool
         db $E6          ; Skean
         db $E7          ; Relic

; Text for Wound status
C3371B:  db "Wounded "

; Text pointers for main menu and save file submenus
C33723:  dw C33804       ; Time
C33725:  dw C3380F       ; Steps
C33727:  dw C33850       ; Order
C33729:  dw C337CB       ; Item
C3372B:  dw C337D2       ; Skills
C33759:  dw C337DB       ; Equip
C3372D:  dw C337E3       ; Relic
C3372F:  dw C337EB       ; Status
C3375B:  dw C337F4       ; Config
C33731:  dw C3377E       ; /
C33733:  dw C33782       ; /
C33735:  dw C33795       ; /
C33737:  dw C33799       ; /
C33739:  dw C337AC       ; /
C3373B:  dw C337B0       ; /
C3373D:  dw C337C3       ; /
C3373F:  dw C337C7       ; /
C33741:  dw C3376F       ; LV
C33743:  dw C33774       ; HP
C33745:  dw C33779       ; MP
C33747:  dw C33786       ; LV
C33749:  dw C3378B       ; HP
C3374B:  dw C33790       ; MP
C3374D:  dw C3379D       ; LV
C3374F:  dw C337A2       ; HP
C33751:  dw C337A7       ; MP
C33753:  dw C337B4       ; LV
C33755:  dw C337B9       ; HP
C33757:  dw C337BE       ; MP
C3375D:  dw C3381C       ; Yes
C3375F:  dw C33822       ; No
C33761:  dw C33827       ; This
C33763:  dw C3382E       ; data?
C33765:  dw C3381C       ; Yes
C33767:  dw C33822       ; No
C33769:  dw C33836       ; Erasing
C3376B:  dw C33840       ; data.
C3376D:  dw C33848       ; Okay?

; Positioned text for main menu and save file submenus
C3376F:  dw $399D : db "LV",$00
C33774:  dw $39DD : db "HP",$00
C33779:  dw $3A1D : db "MP",$00
C3377E:  dw $39EB : db "/",$00
C33782:  dw $3A2B : db "/",$00
C33786:  dw $3B1D : db "LV",$00
C3378B:  dw $3B5D : db "HP",$00
C33790:  dw $3B9D : db "MP",$00
C33795:  dw $3B6B : db "/",$00
C33799:  dw $3BAB : db "/",$00
C3379D:  dw $3C9D : db "LV",$00
C337A2:  dw $3CDD : db "HP",$00
C337A7:  dw $3D1D : db "MP",$00
C337AC:  dw $3CEB : db "/",$00
C337B0:  dw $3D2B : db "/",$00
C337B4:  dw $3E1D : db "LV",$00
C337B9:  dw $3E5D : db "HP",$00
C337BE:  dw $3E9D : db "MP",$00
C337C3:  dw $3E6B : db "/",$00
C337C7:  dw $3EAB : db "/",$00
C337CB:  dw $7939 : db "Item",$00
C337D2:  dw $79B9 : db "Skills",$00
C337DB:  dw $7A39 : db "Equip",$00
C337E3:  dw $7AB9 : db "Relic",$00
C337EB:  dw $7B39 : db "Status",$00
C337F4:  dw $7BB9 : db "Config",$00
C337FD:  dw $7C39 : db "Save",$00
C33804:  dw $7CBB : db "Time",$00
C3380B:  dw $7CFF : db ":",$00
C3380F:  dw $7DB7 : db "Steps",$00
C33817:  dw $7E77 : db "Gp",$00
C3381C:  dw $7ABD : db "Yes",$00
C33822:  dw $7B3D : db "No",$00
C33827:  dw $7937 : db "This",$00
C3382E:  dw $79B7 : db "data?",$00
C33836:  dw $7937 : db "Erasing",$00
C33840:  dw $79B7 : db "data.",$00
C33848:  dw $7A37 : db "Okay?",$00
C33850:  dw $813D : db "Order",$00

; Text pointers for color selection arrow
C3418D:  dw C341A7       ; Window 1
         dw C341AB       ; Window 2
         dw C341AF       ; Window 3
         dw C341B3       ; Window 4
         dw C341B7       ; Window 5
         dw C341BB       ; Window 6
         dw C341BF       ; Window 7

; Positioned spaces for blanking color selection arrow
C3419D:  dw $44F5 : db "       ",$00

; Positioned arrows for wallpaper colors
C341A7:  dw $44F5 : db !up,$00 ; Color 1
C341AB:  dw $44F7 : db !up,$00 ; Color 2
C341AF:  dw $44F9 : db !up,$00 ; Color 3
C341B3:  dw $44FB : db !up,$00 ; Color 4
C341B7:  dw $44FD : db !up,$00 ; Color 5
C341BB:  dw $44FF : db !up,$00 ; Color 6
C341BF:  dw $4501 : db !up,$00 ; Color 7

; Text pointers for Config menu
C34993:  dw C349AA       ; Bat.Mode
         dw C349B5       ; Bat.Speed
         dw C349C1       ; Msg.Speed
         dw C349CD       ; Cmd.Set
         dw C349D7       ; Gauge
         dw C349DF       ; Sound
         dw C3498A       ; Cursor
         dw C349E7       ; Reequip
         dw C3490B       ; Controller
         dw C34A34       ; Mag.Order
         dw C34A40       ; Window
         dw C34A49       ; Color
C34A22:  dw C34A60       ; «========»
         dw C34A6D       ; «========»
         dw C34A7A       ; «========»
C34A28:  dw C34A87       ; R
         dw C34A8B       ; G
         dw C34A8F       ; B
         dw C34A51       ; A..
         dw C34A56       ; B..
         dw C34A5B       ; C..
         dw C3491F       ; Fast
         dw C34926       ; Slow

; Positioned text for Config page 1
C3490B:  dw $3D8F : db "Controller",$00
C34918:  dw $39B5 : db "Wait",$00
C3491F:  dw $3A65 : db "Fast",$00
C34926:  dw $3A75 : db "Slow",$00
C3492D:  dw $3B35 : db "Short",$00
C34935:  dw $3BA5 : db "On",$00
C3493A:  dw $3BB5 : db "Off",$00
C34940:  dw $3C25 : db "Stereo",$00
C34949:  dw $3C35 : db "Mono",$00
C34950:  dw $3CB5 : db "Memory",$00
C34959:  dw $3D25 : db "Optimum",$00
C34963:  dw $3DB5 : db "Multiple",$00
C3496E:  dw $3A25 : db "1 2 3 4 5 6",$00
C3497C:  dw $3AA5 : db "1 2 3 4 5 6",$00
C3498A:  dw $3C8F : db "Cursor",$00
C349A1:  dw $78F9 : db "Config",$00
C349AA:  dw $398F : db "Bat.Mode",$00
C349B5:  dw $3A0F : db "Bat.Speed",$00
C349C1:  dw $3A8F : db "Msg.Speed",$00
C349CD:  dw $3B0F : db "Cmd.Set",$00
C349D7:  dw $3B8F : db "Gauge",$00
C349DF:  dw $3C0F : db "Sound",$00
C349E7:  dw $3D0F : db "Reequip",$00
C349F1:  dw $39A5 : db "Active",$00
C349FA:  dw $3B25 : db "Window",$00
C34A03:  dw $3CA5 : db "Reset",$00
C34A0B:  dw $3D35 : db "Empty",$00
C34A13:  dw $3DA5 : db "Single",$00

; Positioned text for Config page 2
C34A34:  dw $418F : db "Mag.Order",$00
C34A40:  dw $438F : db "Window",$00
C34A49:  dw $440F : db "Color",$00
C34A51:  dw $4225 : db "A",!2dot,$00
C34A56:  dw $42A5 : db "B",!2dot,$00
C34A5B:  dw $4325 : db "C",!2dot,$00
C34A60:  dw $452D : db "«±±±±±±±±»",$00
C34A6D:  dw $45AD : db "«±±±±±±±±»",$00
C34A7A:  dw $462D : db "«±±±±±±±±»",$00
C34A87:  dw $4525 : db "R",$00
C34A8B:  dw $45A5 : db "G",$00
C34A8F:  dw $4625 : db "B",$00
C34A93:  dw $43A5 : db "1 2 3 4 5 6 7 8",$00
C34AA5:  dw $41A5 : db "1 2 3 4 5 6",$00
C34AB3:  dw $4425 : db "Font",$00
C34ABA:  dw $4435 : db "Window",$00
C34AC9:  dw $44B5 : db !pal1,!pal2,!pal3,!pal4,!pal5,!pal6,!pal7,$00

; Relative pointers to Mag.Order strings
C340D2:  db $00,$08,$10  ; Healing, Attack, Effect
         db $00          ; ...
         db $00,$10,$08  ; Healing, Effect, Attack
         db $00          ; ...
         db $08,$10,$00  ; Attack, Effect, Healing
         db $00          ; ...
         db $08,$00,$10  ; Attack, Healing, Effect
         db $00          ; ...
         db $10,$00,$08  ; Effect, Healing, Attack
         db $00          ; ...
         db $10,$08,$00  ; Effect, Attack, Healing

; Mag.Order strings
C34AD3:  db !whit,"Healing"
         db !blck,"Attack "
         db !gray,"Effect "

; Positioned text for Cmd.Set menu
C34AF1:  dw $78CF : db "Arrange",$00

; Positioned text for Controller menu
C34AFB:  dw $7B4D : db "Controller",$00
C34B08:  dw $7C21 : db "Cntlr1",$00
C34B11:  dw $7C33 : db "Cntlr2",$00
C34B1A:  dw $7CA1 : db "Cntlr1",$00
C34B23:  dw $7CB3 : db "Cntlr2",$00
C34B2C:  dw $7D21 : db "Cntlr1",$00
C34B35:  dw $7D33 : db "Cntlr2",$00
C34B3E:  dw $7DA1 : db "Cntlr1",$00
C34B47:  dw $7DB3 : db "Cntlr2",$00

; Positioned text, "MP Needed"
C35889:  dw $7A15 : db "MP",$00
C3588E:  dw $7A4D : db "Needed",$00

; Pointers to skill names for Skills menu
skillnm: dw C35C48       ; Espers
         dw C35C51       ; Magic
         dw C35C59       ; SwdTech
         dw C35C63       ; Blitz
         dw C35C6B       ; Lore
         dw C35C72       ; Rage
         dw C35C79       ; Dance

; Positioned text for Skills menu
C35C48:  dw $790D : db "Espers",$00
C35C51:  dw $798D : db "Magic",$00
C35C59:  dw $7A8D : db "SwdTech",$00
C35C63:  dw $7B0D : db "Blitz",$00
C35C6B:  dw $7B8D : db "Lore",$00
C35C72:  dw $7C0D : db "Rage",$00
C35C79:  dw $7C8D : db "Dance",$00

; Text pointers for Skills menu
C35C81:  dw C35CC2       ; LV
         dw C35CC7       ; HP
         dw C35CCC       ; MP

; Positioned text for Skills submenus
C35C87:  dw $81B7 : db "MP…    ",$00
C35C91:  dw $81B7 : db "Lore",$00
C35C98:  dw $81B7 : db "Rage",$00
C35C9F:  dw $81B7 : db "Dance",$00
C35CA7:  dw $81B7 : db "Espers",$00
C35CB0:  dw $81B7 : db "Blitz",$00
C35CB8:  dw $81B7 : db "SwdTech",$00
C35CC2:  dw $422D : db "LV",$00
C35CC7:  dw $42AD : db "HP",$00
C35CCC:  dw $432D : db "MP",$00
C35CD1:  dw $42BB : db "/",$00
C35CD5:  dw $433B : db "/",$00
C35CD9:             db " has it!",$00
C35CE2:  dw $4439 : db "Skill",$00
C35CEA:  dw $4423 : db "Learn.Rate",$00
C35CF7:           : db "At level up...",$00

; Text pointers for Status menu
C36437:  dw C3646F       ; Status
         dw C36511       ; Your Exp:
         dw C3651D       ; For level up:
         dw C36497       ; Vigor
         dw C364EB       ; Speed
         dw C3649F       ; Stamina
         dw C364A9       ; Mag.Pwr
         dw C364F3       ; Bat.Pwr
         dw C364FD       ; Defense
         dw C364B3       ; Evade %
         dw C36507       ; Mag.Def
         dw C364BD       ; MBlock%

; Text pointers for Status menu
C36455:  dw C36488       ; LV
         dw C3648D       ; HP
         dw C36492       ; MP

; Text pointers for Status menu
C3645B:  dw C36478       ; /
         dw C3647C       ; /
         dw C36480       ; %
         dw C36484       ; %

; Positioned text for Status menu
C3646F:  dw $78CD : db "Status",$00
C36478:  dw $3A6B : db "/",$00
C3647C:  dw $3AAB : db "/",$00
C36480:  dw $7F83 : db "%",$00
C36484:  dw $8883 : db "%",$00
C36488:  dw $3A1D : db "LV",$00
C3648D:  dw $3A5D : db "HP",$00
C36492:  dw $3A9D : db "MP",$00
C36497:  dw $7ECF : db "Vigor  ",!2dot,$00
C364EB:  dw $7F4F : db "Speed  ",!2dot,$00
C3649F:  dw $7FCF : db "Stamina",!2dot,$00
C364A9:  dw $884F : db "Mag.Pwr",!2dot,$00
C364F3:  dw $7E69 : db "Bat.Pwr  ",!2dot,$00
C364FD:  dw $7EE9 : db "Defense  ",!2dot,$00
C364B3:  dw $7F69 : db "Evade %  ",!2dot,$00
C36507:  dw $7FE9 : db "Mag.Def  ",!2dot,$00
C364BD:  dw $8869 : db "MBlock%  ",!2dot,$00
C36511:  dw $7C4D : db "Your Exp:",$00
C3651D:  dw $7D4D : db "For level up:",$00

; Positioned text for actor naming menu
C368E3:  dw $411B : db "Please enter a name.", $00

; Text pointers for Lineup menu
C379C9:  dw C379CF       ; LV
         dw C379D4       ; HP
         dw C379D9       ; MP

; Positioned text for Lineup menu
C379CF:  dw $3A6D : db "LV",$00
C379D4:  dw $3AED : db "HP",$00
C379D9:  dw $3B6D : db "MP",$00
C379DE:  dw $3AFB : db "/",$00
C379E2:  dw $3B7B : db "/",$00

; Positioned text for Lineup menu
C37AAE:  dw $390D : db "Lineup",$00
C37A95:  dw $391D : db "Form   group(s).    ",$00
C37AB7:  dw $391D : db "You need   group(s)!",$00
C37ACE:  dw $391D : db "No one there!       ",$00

; Text for evasion modifiers
C38854:  db "  0",$B0
         db "+10",$0B
         db "+20",$FE
         db "+30",$ED
         db "+40",$FA
         db "+50",$CE
         db "-10",$0F
         db "-20",$DE
         db "-30",$AD
         db "-40",$BA
         db "-50",$BE

; Text for non-evasion stat modifiers
C38880:  db " 0"
         db "+1"
         db "+2"
         db "+3"
         db "+4"
         db "+5"
         db "+6"
         db "+7"
         db " 0"         ; Unused
         db "-1"
         db "-2"
         db "-3"
         db "-4"
         db "-5"
         db "-6"
         db "-7"

; Text pointers for Item menu
C38D10:  dw C38D1D       ; USE
         dw C38D23       ; ARRANGE
         dw C38D2D       ; RARE

; Positioned text for Item menu
C38D16:  dw $790D : db "Item",$00
C38D1D:  dw $791D : db "USE",$00
C38D23:  dw $7927 : db "ARRANGE",$00
C38D2D:  dw $7939 : db "RARE",$00

; Text for gear data menu
C38D34:  db " can be used by:",$00

; Text pointers for gear data menu
C38D45:  dw C38D77       ; Vigor
         dw C38DCB       ; Speed
         dw C38D7F       ; Stamina
         dw C38D89       ; Mag.Pwr
         dw C38DD3       ; Bat.Pwr
         dw C38DDD       ; Defense
         dw C38D93       ; Evade %
         dw C38DE7       ; Mag.Def
         dw C38D9D       ; MBlock%
C38D69:  dw C38DF1       ; 50% Dmg
         dw C38DFB       ; Absorb HP
         dw C38E07       ; No Effect
         dw C38E13       ; Weak pt

; Positioned text for gear data menu
C38D71:  dw $8643 : db "???",$00
C38D77:  dw $842F : db "Vigor   ",!2dot,$00
C38DCB:  dw $84AF : db "Speed   ",!2dot,$00
C38D7F:  dw $852F : db "Stamina ",!2dot,$00
C38D89:  dw $85AF : db "Mag.Pwr ",!2dot,$00
C38DD3:  dw $862F : db "Bat.Pwr ",!2dot,$00
C38DDD:  dw $86AF : db "Defense ",!2dot,$00
C38D93:  dw $872F : db "Evade % ",!2dot,$00
C38DE7:  dw $87AF : db "Mag.Def ",!2dot,$00
C38D9D:  dw $882F : db "MBlock% ",!2dot,$00
C38DF1:  dw $7B8D : db "50% Dmg",$00
C38DFB:  dw $7BA9 : db "Absorb HP",$00
C38E07:  dw $7C8D : db "No Effect",$00
C38E13:  dw $7CA9 : db "Weak pt",$00
C38E1D:  dw $7B8D : db "Attack",$00
C38E26:  dw $822F : db "SwdTech",$00
C38E30:  dw $82AF : db "Runic",$00
C38E38:  dw $832F : db "2-hand",$00

; Positioned text for item usage menu
C38E41:  dw $7A0D : db "Owned:",$00

; Positioned spaces for blanking item count in Item menu
C38E4A:  dw $7ABF : db "   ",$00

; Text pointers for Equip menu
C3A2A6:  dw C3A31A       ; EQUIP
         dw C3A322       ; OPTIMUM
         dw C3A32C       ; RMOVE
         dw C3A334       ; EMPTY
C3A2AE:  dw C3A2CC       ; Head
         dw C3A2D3       ; Body

; Text pointers for Relic menu
C3A2B2:  dw C3A33C       ; EQUIP
         dw C3A344       ; REMOVE
C3A2B6:  dw C3A2DA       ; Relic
         dw C3A2E2       ; Relic

; Positioned text for Equip and Relic menus
C3A2BA:  dw $7A0D : db "R-hand",$00
C3A2C3:  dw $7A8D : db "L-hand",$00
C3A2CC:  dw $7B0D : db "Head",$00
C3A2D3:  dw $7B8D : db "Body",$00
C3A2DA:  dw $7B0D : db "Relic",$00
C3A2E2:  dw $7B8D : db "Relic",$00

; Positioned text for title in Equip and Relic menus
C3A309:  dw $7939 : db "EQUIP",$00
C3A311:  dw $7939 : db "REMOVE",$00

; Positioned text for options in Equip menu
C3A31A:  dw $790D : db "EQUIP",$00
C3A322:  dw $791B : db "OPTIMUM",$00
C3A32C:  dw $792D : db "RMOVE",$00
C3A334:  dw $793B : db "EMPTY",$00

; Positioned text for options in Relic menu
C3A33C:  dw $7911 : db "EQUIP",$00
C3A344:  dw $791F : db "REMOVE",$00

; Text pointers for Equip and Relic menus
C3A34D:  dw C3A371       ; Vigor
         dw C3A3C5       ; Speed
         dw C3A379       ; Stamina
         dw C3A383       ; Mag.Pwr
         dw C3A3CD       ; Bat.Pwr
         dw C3A3D7       ; Defense
         dw C3A38D       ; Evade %
         dw C3A3E1       ; Mag.Def
         dw C3A397       ; MBlock%
         dw C3A3A1       ; ->
         dw C3A3A5       ; ->
         dw C3A3A9       ; ->
         dw C3A3AD       ; ->
         dw C3A3B1       ; ->
         dw C3A3B5       ; ->
         dw C3A3B9       ; ->
         dw C3A3BD       ; ->
         dw C3A3C1       ; ->

; Positioned text for Equip and Relic menus
C3A371:  dw $7CA9 : db "Vigor",$00
C3A379:  dw $7DA9 : db "Stamina",$00
C3A383:  dw $7E29 : db "Mag.Pwr",$00
C3A38D:  dw $7FA9 : db "Evade %",$00
C3A397:  dw $80A9 : db "MBlock%",$00
C3A3A1:  dw $7CBD : db ">",$00
C3A3A5:  dw $7D3D : db ">",$00
C3A3A9:  dw $7DBD : db ">",$00
C3A3AD:  dw $7E3D : db ">",$00
C3A3B1:  dw $7F3D : db ">",$00
C3A3B5:  dw $7FBD : db ">",$00
C3A3B9:  dw $7EBD : db ">",$00
C3A3BD:  dw $803D : db ">",$00
C3A3C1:  dw $80BD : db ">",$00
C3A3C5:  dw $7D29 : db "Speed",$00
C3A3CD:  dw $7EA9 : db "Bat.Pwr",$00
C3A3D7:  dw $7F29 : db "Defense",$00
C3A3E1:  dw $8029 : db "Mag.Def",$00
C3A3EB:  dw $7923 : db "Empty",$00
C3A3F3:  dw $7921 : db "Optimum",$00
C3A3FD:  dw $79A3 : db "Empty",$00
C3A405:  dw $79A1 : db "Optimum",$00
C3A40F:  dw $7A15 : db "Equipment changed.",$00

; Text pointers for final battle lineup
C3AC84:  dw C3AC8A       ; End
         dw C3AC90       ; Reset
         dw C3AC98       ; Determine order

; Positioned text for final battle lineup
C3AC8A:  dw $4011 : db "End",$00
C3AC90:  dw $3991 : db "Reset",$00
C3AC98:  dw $391D : db "Determine order",$00

; Positioned text for Colosseum
C3AD9A:  dw $790D : db "Colosseum",$00
C3ADA6:  dw $7923 : db "Select an Item",$00

; Positioned spaces for blanking challenger's name
C3B406:  dw $7C75 : db "      ",$00

; Positioned Colosseum text
C3B40F:  dw $7D15 : db "Select the challenger",$00
C3B427:  dw $790D : db "?????????????",$00

; Positioned text for shop menu
C3C2FC:  dw $790D : db "Weapon",$00
C3C305:  dw $790F : db "Armor",$00
C3C30D:  dw $790F : db "Item",$00
C3C314:  dw $790D : db "Relics",$00
C3C31D:  dw $790D : db "Vendor",$00
C3C326:  dw $7A0F : db "BUY  SELL  EXIT",$00
C3C338:  dw $7A41 : db "GP",$00
C3C33D:  dw $7B2B : db "GP",$00
C3C342:  dw $7AB3 : db "Owned:",$00
C3C34B:  dw $7BB3 : db "Equipped:",$00
C3C357:  dw $7B8F : db "Bat Pwr",$00
C3C361:  dw $7B8F : db "Defense",$00
C3C36B:  dw $7BA5 : db "…",$00
C3C36F:  dw $791F : db "Hi! Can I help you?",$00
C3C385:  dw $791F : db "Help yourself!",$00
C3C396:  dw $791F : db "How many?",$00
C3C3A2:  dw $791F : db "Whatcha got?",$00
C3C3BD:  dw $791F : db "Bye!          ",$00
C3C3CE:  dw $791F : db "You need more GP!",$00
C3C3E2:  dw $791F : db "Too many!       ",$00
C3C3F5:  dw $791F : db "One's plenty! ",$00

; =========================[ New general functions ]===========================

; Set data bank register to 7E
db7e:    LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         RTS

; Set WRAM address to 7E/9D89
wm9D89:  PHX             ; Save X
         LDX #$9D89      ; 7E/9D89
         BRA wmplx       ; Set WRAM LBs

; Set WRAM address to 7E/9E8B
wm9E8B:  PHX             ; Save X
         LDX #$9E8B      ; 7E/9E8B
wmplx:   STX $2181       ; Set WRAM LBs
         PLX             ; Restore X
         RTS

; Multiply A by 16, 32, or 64
x64:     REP #$20        ; 16-bit A
         ASL A           ; x64
x32r:    REP #$20        ; 16-bit A
x32:     ASL A           ; x32
x16:     ASL A           ; x16
         ASL A           ; x8
         ASL A           ; x4
         ASL A           ; x2
         RTS

; Multiply B by A
mul8:    PHP             ; Save PS
         REP #$20        ; 16-bit A
         STA $004202     ; Set factors
         NOP             ; Waste 2 cycles
         NOP             ; Waste 2 cycles
         LDA $004216     ; Product
         PLP             ; Restore PS
         CLC             ; Prepare ADC
         RTS

; Multiply 8-bit A by Y
mul16:   PHA             ; Save multiplicand
.loop    LDA $004212     ; PPU status
         ASL A           ; H-Blank?
         BPL .loop       ; Loop if not
         PLA             ; Multiplicand
         STA $00211C     ; Set matrix B
         PHY             ; Push multiplier
         PLA             ; Pull low byte
         STA $00211B     ; Set matrix A LB
         PLA             ; Pull high byte
         STA $00211B     ; Set matrix A HB
         LDX $2134       ; Product LBs
         LDA $2136       ; Product HB
         RTS             ; ^ Add 00 if needed

; Clear VWF graphics buffer
clr_vwf: LDX #$A271      ; 7E/A271

; Clear a block of RAM
clr_ram: PHB             ; Save DB
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         STY $4305       ; Set data size
         STX $2181       ; Set WRAM LBs
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         LDX #C30895     ; C3/0895
         STX $4302       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4304       ; Set src HB
         LDA #$80        ; $2180
         STA $4301       ; To WRAM
         LDA #$08        ; 1Rx1B to PPU
         STA $4300       ; Src = Fixed
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         PLB             ; Restore DB
         RTS

; Clear BG2 tilemaps
bg2c_cl: JSR C36A32      ; Clear BG2 map C
bg2b_cl: JSR C36A2D      ; Clear BG2 map B
         JMP C36A28      ; Clear BG2 map A

; Clear BG3 tilemaps
bg3d_cl: JSR C36A4B      ; Clear BG3 map D
bg3c_cl: JSR C36A46      ; Clear BG3 map C
bg3b_cl: JSR C36A41      ; Clear BG3 map B
         JMP C36A3C      ; Clear BG3 map A

; Shift BG1 write row down by 4 rows
e6add4:  JSR e6add2      ; BG1 WR row +2

; Shift BG1 write row down by 2 rows
e6add2:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         RTS

; Add two-digit number to string
add2n:   LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         RTS

; Draw Y spaces
spacedr: JSR wm9E8B      ; WRAM: 7E/9E8B
         JSR spaces      ; Build string
         JMP C37FD_      ; Draw string

; Add Y spaces to string
spaces:  SEP #$20        ; 8-bit A
         LDA #$FF        ; Space char
.loop    STA $2180       ; Add to string
         DEY             ; One less left
         BNE .loop       ; Loop till last
         RTS

; Load fixed-size string from table (variant of C38467)
fw_txt:  JSR wm9E8B      ; WRAM: 7E/9E8B
         STY $FD         ; Set src LBs
         STA $FF         ; Set src HB
         TXA             ; String size
         JSR mul8        ; Number x size
         TAY             ; Index product
.loop    LDA [$FD],Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE .loop       ; Loop till last
         RTS

; Set sprite's position
objpos:  PHY             ; Push coords
         PLA             ; X position
         STA $7E33CA,X   ; Set sprite's
         PLA             ; Y position
         STA $7E344A,X   ; Set sprite's
         RTS

; Set animation table pointer to C3/YYYY
anm_c3:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3

; Set animation table pointer to AA/YYYY
anm_st:  STA $7E35CA,X   ; Set ptr HB
         REP #$20        ; 16-bit A
         TYA             ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Load pointer to portrait's graphics
faceptr: TDC             ; Clear A
         SEP #$20        ; 8-bit A
         TYX             ; Actor's address
         LDA $14,X       ; Status
         AND #$20        ; Imp?
         BEQ .locke      ; Branch if not
         LDA #$0F        ; Use Imp image
         BRA .load       ; Ignore actor
.locke   LDA $00,X       ; Actor
         CMP #$01        ; Locke?
         BEQ .load       ; Branch if so
         LDA $01,X       ; Graphics set
.load    REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36F1B,X  ; GFX pointer
         RTS

; Get item class
itm_cl1: JSR C38321      ; Compute index
itm_cl2: LDX $4216       ; Load it
         TDC             ; Clear A
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         RTS

; Get entry in list of available gear
ldgear1: TDC             ; Clear A
         LDA $4B         ; Gear list slot
ldgear2: TAX             ; Index it
ldgear3: TDC             ; Clear A
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         RTS

; Check if processing Gogo
gogo1:   JSR C32D03      ; Actor's address
gogo2:   LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         RTS

; Save color in CGRAM
cgram:   SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Color index +1
         INX             ; Color index +1
         RTS

; Restore cursor position in previous menu
oldcur:  LDY $8E         ; Old cursor loc
         STY $4F         ; Set as current
         TYA             ; Old cursor column
         STA $4D         ; Set onscreen col
         LDA $90         ; Old scroll pos
;        STA $4A         ; Set as current
         JMP C30E1E      ; Def cursor row

; Set up BG1 H-Shift HDMA
bg1h_:   LDA #$7E        ; Bank: 7E
bg1h:    STA $4364       ; Set CH6 src HB
         STY $4362       ; Set CH6 src LBs
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set CH6 mode
         LDA #$0D        ; $210D
         STA $4361       ; To BG1 H-Scroll
         LDA #$40        ; Channel: 6
         BRA tsb43       ; Queue HDMA-6

; Set up BG1 V-Shift HDMA
bg1v_:   LDA #$7E        ; Bank: 7E
bg1v:    STA $4374       ; Set CH7 src HB
         STY $4372       ; Set CH7 src LBs
         LDA #$02        ; 1Rx2B to PPU
         STA $4370       ; Set CH7 mode
         LDA #$0E        ; $210E
         STA $4371       ; To BG1 V-Scroll
         LDA #$80        ; Channel: 7
         BRA tsb43       ; Queue HDMA-7

; Set up BG3 V-Shift HDMA
bg3v:    STY $4352       ; Set CH5 src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set CH5 src HB
         LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set CH5 mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDA #$20        ; Channel: 5
tsb43:   TSB $43         ; Queue HDMA-5
         RTS

; Draw and upload multiple menu windows
boxes_:  JSR boxes       ; Draw boxes
         JMP C30E52      ; Upload BG2 A+B

; Draw multiple menu windows
boxes:   PHX             ; Save index
         JSR C30341      ; Draw a window
         PLX             ; Window index
         INX             ; Index +1
         INX             ; Index +1
         INX             ; Index +1
         INX             ; Index +1
         LDA.L C30000,X  ; More windows?
         BNE boxes       ; Loop if so
         RTS

; =============================================================================

; Warn on bank overflow
warnpc $C40000

; Blank rest of bank
padbyte $FF : pad $C40000
